GUID Regex Javascript Validator

Search...

⌘K

GUID Regex Javascript Validator

Search...

⌘K


GUID Regex Javascript Validator

GUID Regex Javascript Validator

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.

deadbeef-7331-4123-8123-ba5eba11babe
Possible security issues
This regex appears to be safe.
Explanation
  • [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
Match information
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:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx


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:


^[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}$


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:


function isValidGUID(guid) {
  const guidRegex = /^[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}$/;
  return guidRegex.test(guid);
}

// Test example
const testGUID = "a987fbc9-4bed-3078-cf07-9141ba07c9f3";
console.log(`Is "${testGUID}" valid?`, isValidGUID(testGUID));


Examples


Valid GUID

3f2504e0-4f89-11d3-9a0c-0305e82c3301


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.


Frequently asked questions

What makes a string a valid GUID?×
A valid GUID has 36 characters including hyphens and follows a strict hexadecimal structure with specific version and variant rules.
Is this regex specific to UUID version 4?+
Can JavaScript generate valid GUIDs?+
What’s the difference between GUID and UUID?+
Should I store GUIDs in lowercase?+