xxxxxxxxxx
import uuid
def is_valid_uuid(uuid_string):
try:
uuid_obj = uuid.UUID(uuid_string)
return str(uuid_obj) == uuid_string
except ValueError:
return False
# Example usage
uuid_to_check = "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
result = is_valid_uuid(uuid_to_check)
print(result) # True or False
xxxxxxxxxx
/* Check if string is valid UUID */
function checkIfValidUUID(str) {
// Regular expression to check if string is a valid UUID
const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
return regexExp.test(str);
}
// Use the function
checkIfValidUUID("a24a6ea4-ce75-4665-a070-57453082c256"); // true
checkIfValidUUID("a24a6ea4-ce75-4665-a070"); // false
xxxxxxxxxx
// For test 01234567-9ABC-DEF0-1234-56789ABCDEF0 use Regex
Regex reg = new Regex("/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/");
// with brackets
Regex reg = new Regex("/^\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}?$/");
// use https://regexr.com/ for a REGEX builder