UUID v4
Match UUID v4 identifiers with the standard 8-4-4-4-12 hex format and version check.
What Is This?
This regex pattern matches UUID v4 (random) identifiers. UUIDs are 36-character strings in the format 8-4-4-4-12 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). This pattern specifically validates v4 UUIDs by checking that the version digit is 4 and the variant digits start with 8, 9, A, or B.
How to Use
The Pattern
Use this pattern to validate UUID v4 inputs in forms and APIs. The pattern checks the correct UUID structure: 8 hex digits, hyphen, 4 hex digits, hyphen, '4' followed by 3 hex digits (version 4 check), hyphen, hex digits starting with 8/9/A/B (variant check), hyphen, 12 hex digits.
/^[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}$/iExamples
Valid UUID v4
Matches: 550e8400-e29b-41d4-a716-446655440000 f47ac10b-58cc-4372-a567-0e02b2c3d479 Does not match: 550e8400-e29b-31d4-a716-446655440000 not-a-uuid 12345
Invalid UUID formats
Matches: c9bf9e57-1685-4c89-bafb-ff5af830be8a 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d Does not match: c9bf9e57-1685-3c89-bafb-ff5af830be8a c9bf9e57-1685-4c89-xafb-ff5af830be8a
Related Entries
More from this reference:
Email Address Validation
Validate email addresses with a standard pattern covering most common formats.
URL Pattern
Match HTTP and HTTPS URLs with optional port, path, query string, and fragment.
Phone Number (US/International)
Match US and international phone numbers with optional country code and separators.
Date (YYYY-MM-DD)
Match dates in ISO 8601 YYYY-MM-DD format with basic month and day validation.
Credit Card Number (Generic)
Match generic credit card numbers in grouped or continuous 16-digit format.
Base64 Encoded String
Match standard Base64 encoded strings with optional padding.
Time (HH:MM 24-hour)
Match times in 24-hour HH:MM format with valid hour and minute ranges.
Frequently Asked Questions
What about other UUID versions?
Change the version digit check: v1 (1), v3 (3), v4 (4), v5 (5), v7 (7). For generic UUID validation (any version), use: ^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$.
Should I validate UUID format on the server?
Always validate UUID format server-side before using it in database queries to prevent injection attacks. PostgreSQL has a native uuid type that validates the format automatically.