Blitz3D+ Command Reference

UuidValid ( value$ )

Parameters

value$ - UUID text to validate

Description

Returns true if text is a UUID in one of the three accepted forms.

Save files, mod data and network messages carry ids from sources you do not control - validate before trusting them. Exactly three text forms are accepted:
D form: 00112233-4455-6677-8899-aabbccddeeff (dashed)
N form: 00112233445566778899aabbccddeeff (32 hex digits, no dashes)
Braced: {00112233-4455-6677-8899-aabbccddeeff}

Upper- and lowercase hex both pass. Everything else is rejected - leading or trailing whitespace, prefixes, missing or extra digits, stray punctuation, non-ASCII lookalike characters. The check is strict on purpose: a sloppy id that slips into a save file becomes a permanent compatibility problem.

The all-zero UUID is valid, and so is any version - UuidValid checks the shape of the text, not whether the version bits say 4. Once validated, run ids through NormalizeUuid so the three forms collapse to one canonical spelling before you compare or store them; validating first and normalizing second is the standard import pattern.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: NormalizeUuid, CreateUuid, UuidToBytes, UuidFromBytes.

Example

; UuidValid Example
; -----------------
; Requires Extended mode.

; A save file may contain object ids from many sources.
; UuidValid accepts exactly three text forms:
d_form$="00112233-4455-6677-8899-aabbccddeeff"       ; D: dashed
n_form$="00112233445566778899aabbccddeeff"           ; N: no dashes
braced$="{00112233-4455-6677-8899-aabbccddeeff}"     ; braced GUID

Print "D form   "+d_form+" -> "+UuidValid(d_form)
Print "N form   "+n_form+" -> "+UuidValid(n_form)
Print "Braced   "+braced+" -> "+UuidValid(braced)
Print ""

; Anything else is rejected - validate before trusting save data
bad1$="not-a-uuid"
bad2$="00112233-4455-6677-8899-aabbccddee"           ; too short
Print "Garbage  "+bad1+" -> "+UuidValid(bad1)
Print "Truncated id -> "+UuidValid(bad2)
Print ""

; A freshly generated id always validates
Print "CreateUuid() -> "+UuidValid(CreateUuid())

Print ""
Print "Press any key to close the example"
WaitKey

End

Index