Test for format of a UUID

In a pre-request script, I would like to ensure a particular environment variable’s value has the format of a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

What’s the best way to do this in Postman? Thanks!

By using a regex match.

Postman uses JavaScript under the hood, so this is easily searchable on the web.

javascript - How to test valid UUID/GUID? - Stack Overflow

How to use regular expression in postman script · Issue #4334 · postmanlabs/postman-app-support · GitHub

Which will give you something like the following. I’ve put it in a loop, and I’m getting a random guid using Postman dynamic variables. They have the same format as UUID, but please read the first link for more info on this.

for (let i = 0; i < 10; i++) {
    let uuid = pm.variables.replaceIn('{{$guid}}');
    pm.test(`${uuid} is a valid UUID`, () => {


As always, please remember to make the test fail to ensure its not giving a false positive.

1 Like