Validate format data

How can I validate data format with Postman?

I have the following response body:

“value”: [
{
“cotacaoCompra”: 4.08520,
“cotacaoVenda”: 4.08580,
“dataHoraCotacao”: “2019-10-22 13:10:34.471”
}
]

I need to validate that “cotacaoCompra” has the format “0.00000”

Please, help me!

You could use the .match() function from the chai assertion library and use regex to check the format:

let jsonData = pm.response.json();
pm.test("Check value is correct", () => {  
  pm.expect(jsonData.value[0].cotacaoCompra).to.match(/\d{1}.\d{5}/);
});

It’s not working here.
Result: AssertionError: expected 4.0852 to match /\d{1}.\d{5}/

Apparently postman is not recognizing regex.

It looks like the last 0 is missing from the response value so it’s failing to match the pattern.

You are right. It works now. But if I test with the regex (/\d{1}.\d{3}/) the test pass also.