JAVASCRIPT
Validate UUID (GUID) Format
Implement a regular expression to reliably validate if a given string adheres to the standard Universally Unique Identifier (UUID) or GUID format, particularly for version 4 identifiers.
function isValidUUID(uuid) {
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid);
}
How it works: This JavaScript function leverages a precise regular expression to validate the format of a Universally Unique Identifier (UUID). Specifically designed for version 4 UUIDs, the pattern checks for the correct hexadecimal characters, hyphen positions, and the mandatory '4' in the third segment, along with '8', '9', 'a', or 'b' in the fourth, ensuring standard compliance.