API Reference › Uuid › Uuid.is_valid
method

Uuid.is_valid

Uuid.is_valid(s) -> bool

Reports whether s is a well-formed UUID: exactly 36 characters, hyphens at positions 8, 13, 18 and 23, and hexadecimal digits (either case) everywhere else. This is the guard to run on any UUID that came from outside your program — a save file, a network message, a mod, a command-line flag — before you trust it as an identity.

It checks *shape*, not version: both v4 and v7 IDs (and any other conforming UUID) pass. To also fold a malformed value into a safe default in one step, use Uuid.parse instead.

Parameters

sthe string to check

Example

program Valid {
  entry {
    if Uuid.is_valid("550e8400-e29b-41d4-a716-446655440000") { print(1) }
    if not Uuid.is_valid("not-a-uuid") { print(2) }
  }
}
← All symbols