What Makes a UUID Valid?
A valid UUID must conform to the format defined in RFC 4122. Here's what our validator checks:
Format Requirements
- • Length: 32 hex characters (36 with hyphens)
- • Characters: Only 0-9 and a-f (case insensitive)
- • Hyphens: At positions 8, 13, 18, 23 (optional)
- • Pattern: 8-4-4-4-12 hexadecimal digits
Structural Requirements
- • Version: Position 13 indicates version (1-8)
- • Variant: Position 17 indicates variant (8-b for RFC 4122)
- • Nil UUID: All zeros is valid (special case)
- • Max UUID: All f's is valid (RFC 9562)
UUID Format Pattern
xxxxxxxx-xxxx-Vxxx-Yxxx-xxxxxxxxxxxx
Where V is the version (1-8) and Y is the variant (8, 9, a, or b for RFC 4122 UUIDs).
UUID Version Detection
Our validator automatically detects the UUID version from the 13th character:
| Version | 13th Char | Name | Description |
|---|---|---|---|
| 1 | 1 | Timestamp | Gregorian time + MAC address |
| 2 | 2 | DCE Security | POSIX UID/GID (rarely used) |
| 3 | 3 | MD5 Hash | Name-based (MD5 hash) |
| 4 | 4 | Random | Random or pseudo-random |
| 5 | 5 | SHA-1 Hash | Name-based (SHA-1 hash) |
| 6 | 6 | Reordered Time | Sortable timestamp (RFC 9562) |
| 7 | 7 | Unix Timestamp | Unix time + random (RFC 9562) |
| 8 | 8 | Custom | Vendor-specific (RFC 9562) |
Validate UUIDs in Code
Here's how to validate UUIDs programmatically:
JavaScript
Full guide →
// Using regex
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
function isValidUUID(str) {
return UUID_REGEX.test(str);
}
// Using uuid package
import { validate, version } from 'uuid';
console.log(validate('550e8400-e29b-41d4-a716-446655440000')); // true
console.log(version('550e8400-e29b-41d4-a716-446655440000')); // 4
Python
Full guide →
import uuid
def is_valid_uuid(val):
try:
uuid.UUID(str(val))
return True
except ValueError:
return False
# Check version
my_uuid = uuid.UUID('550e8400-e29b-41d4-a716-446655440000')
print(my_uuid.version) # 4
Java
Full guide →
import java.util.UUID;
public static boolean isValidUUID(String str) {
try {
UUID.fromString(str);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
// Get version
UUID uuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
System.out.println(uuid.version()); // 4