Easily validate GUIDs in JavaScript using our GUID Regex JavaScript Validator. Ensure every identifier matches the correct format of 8-4-4-4-12 hexadecimal characters—ideal for use in API development, form validation, and database management. Combine this tool with our JavaScript Regex Tester for pattern debugging or Email Validator for validating user credentials all in one place.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
What is a GUID (Globally Unique Identifier)?
A GUID is a 128-bit unique identifier commonly used in databases, software development, and APIs to ensure global uniqueness. It’s typically formatted as:
Each x is a hexadecimal character (0–9, a–f). For example: e4f50c60-4d42-11ec-81d3-0242ac130003.
JavaScript can use regular expressions (regex) to validate whether a given string matches this structure.
GUID Regex Pattern for JavaScript
Here is the regex pattern that matches a valid GUID:
Breakdown:
[0-9a-fA-F]{8}: First block – 8 hex characters
[0-9a-fA-F]{4}: Second block – 4 hex characters
[1-5][0-9a-fA-F]{3}: Third block – version field
[89abAB][0-9a-fA-F]{3}: Fourth block – variant field
[0-9a-fA-F]{12}: Final block – 12 hex characters
How to Validate GUIDs in JavaScript
Here’s a complete working code snippet:
Examples
Valid GUID
Invalid GUIDs
3f2504e04f8911d39a0c0305e82c3301 (Missing hyphens)
3f25-04e0-4f89-11d3-9a0c (Too short)
ZZZ504e0-4f89-11d3-9a0c-0305e82c3301 (Invalid hex characters)
Uses of GUID Regex Validation
Database IDs: Ensure unique identifiers for database rows.
API Requests: Securely track request identifiers or session tokens.
Form Input Validation: Confirm GUID format for fields submitted via forms.
Distributed Systems: Uniquely identify resources across systems or services.
Pro Tips
Always convert GUIDs to lowercase or uppercase before validation if your app enforces a specific casing.
Consider client- and server-side validation to avoid tampering or malformed data entries.
If using random GUID generation, test it frequently using the GUID Validator to ensure format consistency.
Don’t confuse UUID v4 and GUID—they share formats but differ in generation logic.