Regex and type checks in API tests, for values that change every run
You can't assert that a new order's id equals ord_8f3k2x9q: it's different every time. But you can assert that it looks like an order id. Most fields in a response are like that. Checking their shape catches real bugs (a numeric id where a string was promised, a timestamp without a time zone, an empty token) without making tests brittle.
Type checks
On the request's Tests tab:
| Field | Source | Path | Operator | Expected |
|---|---|---|---|---|
| id is text | JSON body | $.id | is type | string |
| total is a number | JSON body | $.total | is type | number |
| paid is a boolean | JSON body | $.paid | is type | boolean |
| items is a list | JSON body | $.items | is type | array |
| note may be empty | JSON body | $.note | is type | null |
Type checks catch the quiet breaking changes: an id that becomes a number after a database migration, a boolean sent as "true", a list that becomes null when it's empty.
Regex checks
| Field | Path | Pattern |
|---|---|---|
| Prefixed id | $.id | ^ord_[a-z0-9]{8,}$ |
| UUID | $.requestId | ^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ |
| ISO 8601 UTC timestamp | $.createdAt | ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$ |
| Date only | $.dueDate | ^\d{4}-\d{2}-\d{2}$ |
| Currency code | $.currency | ^[A-Z]{3}$ |
| Money as decimal string | $.amount | ^-?\d+\.\d{2}$ |
| HTTPS URL | $.receiptUrl | ^https:// |
| Email (rough) | $.email | ^[^@\s]+@[^@\s]+\.[^@\s]+$ |
| JWT | $.access_token | ^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$ |
| Semantic version | $.version | ^\d+\.\d+\.\d+$ |
A pattern can be written plainly (^inv_) or between slashes with flags (/^inv_/i for case-insensitive).
Headers take regexes too: source Header, path X-Request-Id, matches regex, a UUID pattern.
Anchor your patterns
\d{4}-\d{2}-\d{2} matches 2026-11-24, and also created on 2026-11-24 maybe. With ^ and $ it matches only a bare date. Unanchored patterns are the most common reason a format check passes when it shouldn't.
The same in a script
When you need several fields or a loop:
const order = pm.response.json();
pm.test('order id format', () => pm.expect(order.id).to.match(/^ord_[a-z0-9]{8,}$/));
pm.test('createdAt is UTC ISO 8601', () => pm.expect(order.createdAt).to.match(/Z$/));
pm.test('every item has a numeric quantity', () => {
order.items.forEach((item) => pm.expect(item.quantity).to.be.a('number'));
});Format plus value
For timestamps, the format alone isn't the whole story. A createdAt in 1970 or next year is well-formed and wrong:
const created = Date.parse(pm.response.json().createdAt);
pm.test('createdAt is within the last minute', () => {
pm.expect(Date.now() - created).to.be.within(0, 60000);
});Give it a little slack for clock differences between your machine and the server. See testing dates and time zones for more.
One rule for the whole API
If every resource id in your API starts with a prefix and every timestamp ends in Z, write those rules once, on the collection's Tests tab, for the fields every response has ($.id, $.createdAt). Every request inherits them. Endpoints that return lists need different paths, so put them in their own folder.