# Test for format of a UUID

**URL:** <https://community.postman.com/t/test-for-format-of-a-uuid/44358>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [February 23, 2023, 2:03am UTC](https://community.postman.com/t/test-for-format-of-a-uuid/44358 "2023-02-23T02:03:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 23, 2023, 11:04am UTC](https://community.postman.com/t/test-for-format-of-a-uuid/44358/2 "2023-02-23T11:04:14Z")

</div>

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](https://stackoverflow.com/questions/7905929/how-to-test-valid-uuid-guid)

[How to use regular expression in postman script · Issue #4334 · postmanlabs/postman-app-support · GitHub](https://github.com/postmanlabs/postman-app-support/issues/4334)

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.

```auto
for (let i = 0; i < 10; i++) {
    let uuid = pm.variables.replaceIn('{{$guid}}');
    pm.test(`${uuid} is a valid UUID`, () => {
        console.log(uuid);
        pm.expect(uuid).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
    });
}

```

![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/5/a5708c16c8aa12618d0ab983a25221c2ac79ad4b.png)

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

---

_[View the full topic](https://community.postman.com/t/test-for-format-of-a-uuid/44358)._
