Need to validate UUID strings in your application? This guide covers the UUID Regex Pattern API, which provides patterns for validating UUID formats, detecting UUID versions, and handling various formatting styles like with or without dashes.
UUID Format Structure
A UUID (Universally Unique Identifier) is a 128-bit identifier typically represented as 32 hexadecimal digits in the format:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
Where M indicates the version and N indicates the variant. For example: 550e8400-e29b-41d4-a716-446655440000
UUID Versions
The version digit (M) indicates how the UUID was generated:
- Version 1: Time-based UUID (starts with 1 in position 13)
- Version 3: Name-based using MD5 hash
- Version 4: Random UUID (most common, starts with 4)
- Version 5: Name-based using SHA-1 hash
Using the UUID Regex API
TinyFn provides UUID validation patterns:
GET https://api.tinyfn.io/v1/regex/patterns/uuid
Headers: X-API-Key: your-api-key
{
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
"type": "any",
"description": "Validates any valid UUID (v1-v5)",
"flags": "i",
"examples": {
"valid": ["550e8400-e29b-41d4-a716-446655440000", "6ba7b810-9dad-11d1-80b4-00c04fd430c8"],
"invalid": ["not-a-uuid", "550e8400-e29b-61d4-a716-446655440000"]
}
}
Parameters
| Parameter | Type | Description |
|---|---|---|
version |
integer | Specific version to validate: 1, 3, 4, or 5. Default: any |
allow_no_dashes |
boolean | Also match UUIDs without dashes. Default: false |
case_sensitive |
boolean | Require lowercase (true) or allow any case (false). Default: false |
Code Examples
JavaScript / Node.js
// Get UUID v4 specific pattern
const response = await fetch(
'https://api.tinyfn.io/v1/regex/patterns/uuid?version=4',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const { pattern, flags } = await response.json();
// Validate UUIDs
const uuidRegex = new RegExp(pattern, flags);
console.log(uuidRegex.test('f47ac10b-58cc-4372-a567-0e02b2c3d479')); // true (v4)
console.log(uuidRegex.test('6ba7b810-9dad-11d1-80b4-00c04fd430c8')); // false (v1)
Python
import requests
import re
response = requests.get(
'https://api.tinyfn.io/v1/regex/patterns/uuid',
params={'allow_no_dashes': 'true'},
headers={'X-API-Key': 'your-api-key'}
)
pattern = response.json()['pattern']
uuid_pattern = re.compile(pattern, re.IGNORECASE)
# Both formats will match
print(bool(uuid_pattern.match('550e8400-e29b-41d4-a716-446655440000'))) # True
print(bool(uuid_pattern.match('550e8400e29b41d4a716446655440000'))) # True
cURL
curl "https://api.tinyfn.io/v1/regex/patterns/uuid?version=4&case_sensitive=true" \
-H "X-API-Key: your-api-key"
Common Use Cases
- API Validation: Validate UUID parameters in API requests
- Database IDs: Validate primary keys before database operations
- Form Validation: Validate UUID inputs in forms
- URL Routing: Match UUID patterns in URL paths
- Data Migration: Validate UUIDs during data import
Best Practices
- Case insensitive: UUIDs are typically case-insensitive; allow both cases
- Normalize format: Convert to lowercase with dashes for storage
- Version validation: Only validate specific versions if your system requires it
- Handle nil UUID: Decide if 00000000-0000-0000-0000-000000000000 is valid for your use case
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-regex": {
"url": "https://api.tinyfn.io/mcp/regex/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all regex tools available via MCP in our Regex MCP Tools for AI Agents guide.
Try the UUID Regex Pattern API
Get your free API key and start validating UUIDs reliably.
Get Free API Key