JavaScript UUID Regex Validator

Test UUID v4 and v7 patterns against passing and failing examples. Use the version and variant checks that match what your form, API or import accepts.

Validate UUID v7

A canonical UUID v7 starts its third group with 7. The fourth group starts with 8, 9, a or b for the RFC variant.

const uuidV7 = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

The tester includes the RFC example, a v4 UUID and a v7-shaped value with the wrong variant. Only the RFC example should match. Use just the case-insensitive flag when checking an individual field.

Try the UUID v7 regex

To read the encoded time or check a full list, open the bulk UUID validator. It can export duplicate lines and timestamps as CSV. See the UUID v7 specification.

How to validate a UUID regex

  1. Decide whether the field accepts only UUID v4 values, UUID versions 1 through 5, lowercase canonical values, or compact 32-character hex IDs.
  2. Use `^` and `$` when `regex.test(value)` must approve the whole UUID string instead of a valid-looking fragment inside a larger value.
  3. Check the version nibble and variant nibble deliberately when the app expects UUID v4, not any hyphenated 128-bit identifier.
  4. Test uppercase input, missing hyphens, wrong group lengths, invalid hex characters, surrounding text, and legacy UUID versions before shipping.
  5. After regex passes, use application logic for uniqueness, database lookup, authorization, and any ID ownership rules.

UUID expressions to test

UUID v4 validator

^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$

Pass: 550e8400-e29b-41d4-a716-446655440000, 123e4567-e89b-42d3-a456-426614174000

Fail: 550e8400-e29b-11d4-a716-446655440000, not-a-uuid

Use this when generated identifiers must be version 4 UUIDs with the standard variant bits.

UUID versions 1 through 5

^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$

Pass: 550e8400-e29b-41d4-a716-446655440000, 550e8400-e29b-11d4-a716-446655440000

Fail: 550e8400-e29b-91d4-a716-446655440000, 550e8400-e29b-41d4-z716-446655440000

Good for APIs that accept older UUID versions but still require canonical hyphen positions and variant bits.

Lowercase canonical UUID v4

^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$

Pass: 550e8400-e29b-41d4-a716-446655440000

Fail: 550E8400-E29B-41D4-A716-446655440000, 550e8400e29b41d4a716446655440000

Use this when storage, routing, or cache keys must stay lowercase and canonical.

Compact 32-character UUID source

^[0-9a-fA-F]{32}$

Pass: 550e8400e29b41d4a716446655440000

Fail: 550e8400-e29b-41d4-a716-446655440000, 550e8400e29b41d4a71644665544

Only use this if your system intentionally accepts compact IDs and normalizes them before display or storage.

Pass and fail samples for UUID validators

Should pass UUID v4

550e8400-e29b-41d4-a716-446655440000, 123e4567-e89b-42d3-a456-426614174000

Should fail UUID v4

not-a-uuid, 550e8400e29b41d4a716446655440000, id=550e8400-e29b-41d4-a716-446655440000

Version decision

550e8400-e29b-11d4-a716-446655440000, 550e8400-e29b-51d4-a716-446655440000

Case decision

550E8400-E29B-41D4-A716-446655440000, 550e8400-e29b-41d4-a716-446655440000

Copy-ready JavaScript regex.test examples

Boolean UUID v4 regex.test check

const uuidV4Pattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
const isUuidV4 = uuidV4Pattern.test(value);

Use a non-global anchored regex for a single yes or no validator result.

Validate submitted ID rows

const uuidV4Pattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
const invalidIds = values.filter((value) => !uuidV4Pattern.test(value.trim()));

Trim only if the browser, API, and tests all use the same normalization rule.

Normalize casing after validation

const uuidV4Pattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
const canonicalId = uuidV4Pattern.test(value) ? value.toLowerCase() : null;

Regex approves the shape. Canonical casing should be an explicit application decision.

Avoid loose partial matches

const looseUuid = /[0-9a-f-]{36}/i;
looseUuid.test('id=550e8400-e29b-41d4-a716-446655440000'); // true, but the field is not only a UUID

Loose extraction patterns are useful for logs, but they are too permissive for a field validator.

UUID regex decisions to make first

  • Does the product require UUID v4 specifically, or can older UUID versions pass?
  • Should uppercase UUIDs pass, or should the UI normalize to lowercase before validation?
  • Are braces, URN prefixes, or compact 32-character UUIDs intentionally supported?
  • Will route params and API body fields use the exact same UUID expression?
  • Can the value include surrounding text, or must the whole field be only the UUID?
  • Do tests prove that invalid version, variant, length, and hex-character cases fail?

Test a UUID regex now

Open the live tester with a UUID v4 validator and mixed samples already loaded. The failing rows are included to expose missing hyphens, non-UUID text, wrong versions, and partial-match problems.

Test UUID Regex

Related Pages on Regex Tester

JavaScript UUID Regex FAQ

What is a JavaScript regex UUID validator?

It is an anchored regular expression used with the JavaScript RegExp engine to decide whether a string matches an accepted UUID format, such as canonical UUID v4.

Should a UUID validator check the version number?

Yes when your app expects a specific UUID version. For UUID v4, the third group should start with 4 and the variant group should start with 8, 9, a, or b.

Can regex prove a UUID exists in the database?

No. Regex can validate text shape and version bits, but existence, ownership, uniqueness, and authorization must be checked in application or database logic.

Should JavaScript UUID regex use the global flag with regex.test?

No for normal field validation. A global regex changes lastIndex between calls, so repeated `.test()` checks can become unreliable.