Back to Home

UUID / GUID Validation Regex

CronOS Team
regexuuidguidvalidationtutorial

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern

UUID / GUID Validation Regex

Validate UUID (Universally Unique Identifier) or GUID (Globally Unique Identifier) in standard 8-4-4-4-12 hexadecimal format.

Pattern Breakdown

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

Components

ComponentDescriptionMatches
^Start anchorEnsures match from string start
[0-9a-fA-F]{8}First groupExactly 8 hex digits
-SeparatorLiteral hyphen
[0-9a-fA-F]{4}Second groupExactly 4 hex digits
-SeparatorLiteral hyphen
[0-9a-fA-F]{4}Third groupExactly 4 hex digits
-SeparatorLiteral hyphen
[0-9a-fA-F]{4}Fourth groupExactly 4 hex digits
-SeparatorLiteral hyphen
[0-9a-fA-F]{12}Fifth groupExactly 12 hex digits
$End anchorEnsures match to string end

Character Classes

  • [0-9a-fA-F] - Hexadecimal digits: 0-9, a-f, A-F
  • {8} - Quantifier: exactly 8 occurrences
  • {4} - Quantifier: exactly 4 occurrences
  • {12} - Quantifier: exactly 12 occurrences

Examples

Valid:

  • 550e8400-e29b-41d4-a716-446655440000
  • 550E8400-E29B-41D4-A716-446655440000 (uppercase)
  • 550e8400-e29b-41d4-a716-446655440000
  • 00000000-0000-0000-0000-000000000000

Invalid:

  • 550e8400e29b41d4a716446655440000 (missing hyphens)
  • 550e8400-e29b-41d4-a716-44665544000 (missing digit)
  • 550e8400-e29b-41d4-a716-4466554400000 (extra digit)
  • 550g8400-e29b-41d4-a716-446655440000 (invalid hex character)
  • 550e8400-e29b-41d4-a716 (incomplete)

Implementation

JavaScript

javascript
const uuidRegex = /^[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}$/;
uuidRegex.test('550e8400-e29b-41d4-a716-446655440000'); // true
uuidRegex.test('550E8400-E29B-41D4-A716-446655440000'); // true
uuidRegex.test('550e8400e29b41d4a716446655440000'); // false (missing hyphens)

Python

python
import re
uuid_regex = r'^[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}$'
bool(re.match(uuid_regex, '550e8400-e29b-41d4-a716-446655440000'))  # True
bool(re.match(uuid_regex, '550e8400e29b41d4a716446655440000'))  # False

Go

go
uuidRegex := regexp.MustCompile(`^[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}$`)
uuidRegex.MatchString("550e8400-e29b-41d4-a716-446655440000") // true
uuidRegex.MatchString("550e8400e29b41d4a716446655440000") // false

Limitations

  1. Format only: Validates format, not actual UUID uniqueness
  2. No version validation: Doesn't validate UUID version (1-5) or variant
  3. Fixed format: Only validates standard format with hyphens
  4. No nil UUID check: Accepts all-zeros UUID

When to Use

  • UUID format validation
  • Database ID validation
  • API parameter validation
  • When you need to verify UUID structure
  • Unique identifier input forms

For production, consider:

  • Supporting UUIDs without hyphens if needed
  • Validating UUID version and variant
  • Using UUID parsing libraries
  • Generating UUIDs with proper libraries
  • Normalizing to lowercase or uppercase

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern