GUID Regex Javascript Validator

Search...

⌘K

GUID Regex Javascript Validator

Search...

⌘K


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:

  • " ^ " : Anchor the pattern to the start and end of the string, ensuring the entire string matches the GUID format and nothing else sneaks in.

  • "[0-9a-fA-F]{8}" : First block – 8 hex characters, the first chunk of the GUID.

  • " - " : A literal hyphen separates each block.

  • " [0-9a-fA-F]{4} ": Second block – 4 hex characters, made up of 4 hex characters.

  • " - " : Another hyphen

  • " [1-5][0-9a-fA-F]{3} " : Third block – version field, starting with a digit from 1 to 5 to indicate the GUID version, followed by 3 more hex characters.

  • " - " : Another hyphen

  • " [89abAB][0-9a-fA-F]{3} " : Fourth block – variant field, starting with one of 8, 9, a, b (case-insensitive) for the variant, then 3 more hex chars.

  • " - " : Last hyphen before the final group.

  • " [0-9a-fA-F]{12} ": Final block – 12 hex characters, 2 hex characters wrap up the GUID.


Let’s break down what this regex is ensuring:

  • Anchors: The and at the beginning and end ensure the entire string is tested, not just a substring.

  • Hexadecimal Ranges: captures any digit or letter a–f (either case), perfectly matching the allowed GUID characters.

  • Dashes: The hyphens () are required at specific locations, dividing the GUID into its traditional 8-4-4-4-12 format.

  • Version Field: The ensures that the third block always starts with a version number between 1 and 5, as per GUID specs.

  • Variant Field: The at the start of the fourth block restricts the variant portion to accepted values.

  • Exact Length: No room for extra or missing characters—just the right number of hex digits and dashes.

This structure makes the pattern robust against common mistakes, like missing hyphens, extra characters, or invalid version/variant fields. It’s strict, concise, and ready for use in your JavaScript code!


This pattern ensures:

  • The string is the exact length and structure of a GUID.

  • Only valid hexadecimal characters are allowed.

  • The correct version and variant bits are present, which is crucial for GUID integrity.

The regex is case-insensitive for hexadecimal digits, but picky about placement of hyphens, version, and variant bits, making it robust for real-world validation.

Now, let's see how to put this regex to work in your JavaScript code.


Additional Regex Essentials

  • [abc]: matches a single character of a, b, or c

  • [^abc]: matches any character except a, b, or c

  • [a-zA-Z]: matches any letter, uppercase or lowercase

  • .: matches any single character

  • ab: matches either 'a' or 'b'

  • \s: matches any whitespace character

  • \S: matches any non-whitespace character

  • \d: matches any digit

  • \D: matches any non-digit

  • \w: matches any word character (letters, digits, or underscore)

  • \W: matches any non-word character

  • (?:...): non-capturing group

  • (...): capturing group

  • a{3}: exactly 3 of 'a'

  • a{3,}: 3 or more of 'a'

  • a{3,6}: between 3 and 6 of 'a'

  • \b: word boundary

  • \B: non-word boundary


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)


More Example Cases

To help clarify what a GUID is—and isn’t—here are some additional examples you might encounter when validating user input or API responses:

Valid formats:

  • 3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Standard, no braces)

  • {3f2504e0-4f89-11d3-9a0c-0305e82c3301} (With curly braces)

  • 3f2504e04f8911d39a0c0305e82c3301 (No hyphens, sometimes allowed in loose checks)

  • {3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)


Invalid formats:

  • 3g2504e0-4f89-11d3-9a0c-0305e82c3301 (Non-hex character in first group)

  • 3f2504e0-zz89-11d3-9a0c-0305e82c3301 (Non-hex character in second group)

  • 3f2504e0-4f89-11d3z-9a0c-0305e82c3301 (Non-hex character in third group)

  • {3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Missing closing brace)

  • 3f2504e0-4f89-11d3-9a0c-0305e82c3301} (Missing opening brace)

  • 3f2504-4f89-11d3-9a0c-0305e82c3301 (Incorrect number of characters in first group)

  • 3f2504e0-4f8-11d3-9a0c-0305e82c3301 (Incorrect number of characters in second group)

  • 3f2504e0-4f89-113-9a0c-0305e82c3301 (Incorrect number of characters in third group)

  • 3f2504e04f89-11d3-9a0c-0305e82c3301 (Incorrect grouping)


Edge cases:

  • {3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)

  • 3f25-04e0-4f89-11d3-9a0c0305e82c3301 (Hyphens in wrong places)

  • {3f2504e0}-4f89-11d3-9a0c-0305e82c3301 (Mixed format with braces and misplaced hyphens)


When validating GUIDs, watch out not only for the length and hyphen placement but also for invalid characters (anything outside 0-9, a-f, or A-F) and mismatched or missing braces in wrapped formats. Checking these cases will help ensure your regex validation catches subtle mistakes that could otherwise slip through.


Interpreting the Match Information

When reviewing the match information, you'll notice each match is detailed with its position in the source text, the exact substring matched, and any captured groups. Here’s how to make sense of it all:

  • Match Span: This is shown as two numbers (e.g., 94–130), which mark the start and end index where the match occurs. Handy for troubleshooting or extracting data programmatically.

  • Matched String: This represents exactly what the regular expression found at that position—a quick way to see what was caught.

Understanding Captured Groups


Captured groups break down the inside of each match:

  • Group Number: Each group corresponds to a parenthetical section of your regex. Group 1 refers to the first set of parentheses, Group 2 to the second, and so on.

  • Group Span: Like the main match, each group’s span shows precisely where in the text the group began and ended. This lets you zero in on specific submatches.

  • Group Value: This column reveals what text the group actually matched. If you see “empty string,” that means the group didn’t capture anything for this particular match—perhaps because part of the pattern was optional.

In short, the match information gives you a map: you can see exactly what and where your pattern is identifying in your data, right down to the most granular grouping. This insight can be useful whether you’re debugging a regex, slicing apart complex data formats, or simply wanting a detailed account of what matches your pattern found.


Available Functions

Within this regex tool, you can do more than just find matches in your text. There’s support for:

  • Performing substitutions, so you can quickly replace patterns with your desired text

  • Listing all matches in one convenient view

  • Running unit tests to make sure your regular expressions perform as expected across different cases

Whether you’re checking for accuracy or automating text edits, these functions help streamline your workflow.


Performance Overview

When run against a sizable test string, this regular expression successfully identified 1,004 matches. The total time taken to execute was approximately 89.88 milliseconds, making it relatively efficient even with a large dataset.


Supported Regex Flavors

Regular expressions come in a variety of "flavors," each tailored to the quirks and needs of particular programming environments. Here are some of the most commonly supported types:

  • PCRE2 (used in modern PHP, version 7.3 and above)

  • PCRE (common in older PHP releases)

  • ECMAScript (the flavor used in JavaScript)

  • Python (as interpreted by Python's re library)

  • Golang (Go's built-in regex engine)

  • Java 8 (Java’s regex capabilities as of version 8)

  • .NET 7.0 (used in C# and other .NET languages)

  • Rust (the regular expression crate for Rust projects)

Each flavor has its own syntax rules and supported features, so double-check compatibility when switching between languages and environments.


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.


Additional Helpful Tools


  • Code Generator: Instantly create JavaScript snippets for integrating your GUID regex into your projects.

  • Regex Debugger: Step through your regular expressions to spot errors and fine-tune your patterns.

  • Export Matches: Effortlessly export your regex match results for documentation or further analysis.

  • Benchmark Regex: Measure regex performance to ensure your validation remains efficient, even at scale.

With everything at your fingertips, validating GUIDs and related patterns has never been easier or more reliable.


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?+

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:

  • " ^ " : Anchor the pattern to the start and end of the string, ensuring the entire string matches the GUID format and nothing else sneaks in.

  • "[0-9a-fA-F]{8}" : First block – 8 hex characters, the first chunk of the GUID.

  • " - " : A literal hyphen separates each block.

  • " [0-9a-fA-F]{4} ": Second block – 4 hex characters, made up of 4 hex characters.

  • " - " : Another hyphen

  • " [1-5][0-9a-fA-F]{3} " : Third block – version field, starting with a digit from 1 to 5 to indicate the GUID version, followed by 3 more hex characters.

  • " - " : Another hyphen

  • " [89abAB][0-9a-fA-F]{3} " : Fourth block – variant field, starting with one of 8, 9, a, b (case-insensitive) for the variant, then 3 more hex chars.

  • " - " : Last hyphen before the final group.

  • " [0-9a-fA-F]{12} ": Final block – 12 hex characters, 2 hex characters wrap up the GUID.


Let’s break down what this regex is ensuring:

  • Anchors: The and at the beginning and end ensure the entire string is tested, not just a substring.

  • Hexadecimal Ranges: captures any digit or letter a–f (either case), perfectly matching the allowed GUID characters.

  • Dashes: The hyphens () are required at specific locations, dividing the GUID into its traditional 8-4-4-4-12 format.

  • Version Field: The ensures that the third block always starts with a version number between 1 and 5, as per GUID specs.

  • Variant Field: The at the start of the fourth block restricts the variant portion to accepted values.

  • Exact Length: No room for extra or missing characters—just the right number of hex digits and dashes.

This structure makes the pattern robust against common mistakes, like missing hyphens, extra characters, or invalid version/variant fields. It’s strict, concise, and ready for use in your JavaScript code!


This pattern ensures:

  • The string is the exact length and structure of a GUID.

  • Only valid hexadecimal characters are allowed.

  • The correct version and variant bits are present, which is crucial for GUID integrity.

The regex is case-insensitive for hexadecimal digits, but picky about placement of hyphens, version, and variant bits, making it robust for real-world validation.

Now, let's see how to put this regex to work in your JavaScript code.


Additional Regex Essentials

  • [abc]: matches a single character of a, b, or c

  • [^abc]: matches any character except a, b, or c

  • [a-zA-Z]: matches any letter, uppercase or lowercase

  • .: matches any single character

  • ab: matches either 'a' or 'b'

  • \s: matches any whitespace character

  • \S: matches any non-whitespace character

  • \d: matches any digit

  • \D: matches any non-digit

  • \w: matches any word character (letters, digits, or underscore)

  • \W: matches any non-word character

  • (?:...): non-capturing group

  • (...): capturing group

  • a{3}: exactly 3 of 'a'

  • a{3,}: 3 or more of 'a'

  • a{3,6}: between 3 and 6 of 'a'

  • \b: word boundary

  • \B: non-word boundary


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)


More Example Cases

To help clarify what a GUID is—and isn’t—here are some additional examples you might encounter when validating user input or API responses:

Valid formats:

  • 3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Standard, no braces)

  • {3f2504e0-4f89-11d3-9a0c-0305e82c3301} (With curly braces)

  • 3f2504e04f8911d39a0c0305e82c3301 (No hyphens, sometimes allowed in loose checks)

  • {3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)


Invalid formats:

  • 3g2504e0-4f89-11d3-9a0c-0305e82c3301 (Non-hex character in first group)

  • 3f2504e0-zz89-11d3-9a0c-0305e82c3301 (Non-hex character in second group)

  • 3f2504e0-4f89-11d3z-9a0c-0305e82c3301 (Non-hex character in third group)

  • {3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Missing closing brace)

  • 3f2504e0-4f89-11d3-9a0c-0305e82c3301} (Missing opening brace)

  • 3f2504-4f89-11d3-9a0c-0305e82c3301 (Incorrect number of characters in first group)

  • 3f2504e0-4f8-11d3-9a0c-0305e82c3301 (Incorrect number of characters in second group)

  • 3f2504e0-4f89-113-9a0c-0305e82c3301 (Incorrect number of characters in third group)

  • 3f2504e04f89-11d3-9a0c-0305e82c3301 (Incorrect grouping)


Edge cases:

  • {3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)

  • 3f25-04e0-4f89-11d3-9a0c0305e82c3301 (Hyphens in wrong places)

  • {3f2504e0}-4f89-11d3-9a0c-0305e82c3301 (Mixed format with braces and misplaced hyphens)


When validating GUIDs, watch out not only for the length and hyphen placement but also for invalid characters (anything outside 0-9, a-f, or A-F) and mismatched or missing braces in wrapped formats. Checking these cases will help ensure your regex validation catches subtle mistakes that could otherwise slip through.


Interpreting the Match Information

When reviewing the match information, you'll notice each match is detailed with its position in the source text, the exact substring matched, and any captured groups. Here’s how to make sense of it all:

  • Match Span: This is shown as two numbers (e.g., 94–130), which mark the start and end index where the match occurs. Handy for troubleshooting or extracting data programmatically.

  • Matched String: This represents exactly what the regular expression found at that position—a quick way to see what was caught.

Understanding Captured Groups


Captured groups break down the inside of each match:

  • Group Number: Each group corresponds to a parenthetical section of your regex. Group 1 refers to the first set of parentheses, Group 2 to the second, and so on.

  • Group Span: Like the main match, each group’s span shows precisely where in the text the group began and ended. This lets you zero in on specific submatches.

  • Group Value: This column reveals what text the group actually matched. If you see “empty string,” that means the group didn’t capture anything for this particular match—perhaps because part of the pattern was optional.

In short, the match information gives you a map: you can see exactly what and where your pattern is identifying in your data, right down to the most granular grouping. This insight can be useful whether you’re debugging a regex, slicing apart complex data formats, or simply wanting a detailed account of what matches your pattern found.


Available Functions

Within this regex tool, you can do more than just find matches in your text. There’s support for:

  • Performing substitutions, so you can quickly replace patterns with your desired text

  • Listing all matches in one convenient view

  • Running unit tests to make sure your regular expressions perform as expected across different cases

Whether you’re checking for accuracy or automating text edits, these functions help streamline your workflow.


Performance Overview

When run against a sizable test string, this regular expression successfully identified 1,004 matches. The total time taken to execute was approximately 89.88 milliseconds, making it relatively efficient even with a large dataset.


Supported Regex Flavors

Regular expressions come in a variety of "flavors," each tailored to the quirks and needs of particular programming environments. Here are some of the most commonly supported types:

  • PCRE2 (used in modern PHP, version 7.3 and above)

  • PCRE (common in older PHP releases)

  • ECMAScript (the flavor used in JavaScript)

  • Python (as interpreted by Python's re library)

  • Golang (Go's built-in regex engine)

  • Java 8 (Java’s regex capabilities as of version 8)

  • .NET 7.0 (used in C# and other .NET languages)

  • Rust (the regular expression crate for Rust projects)

Each flavor has its own syntax rules and supported features, so double-check compatibility when switching between languages and environments.


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.


Additional Helpful Tools


  • Code Generator: Instantly create JavaScript snippets for integrating your GUID regex into your projects.

  • Regex Debugger: Step through your regular expressions to spot errors and fine-tune your patterns.

  • Export Matches: Effortlessly export your regex match results for documentation or further analysis.

  • Benchmark Regex: Measure regex performance to ensure your validation remains efficient, even at scale.

With everything at your fingertips, validating GUIDs and related patterns has never been easier or more reliable.


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?+