← Back to Discord Forum

Is there a way to assert if value is a guid/uuid?

Understandably, guid / uuid is usually not hard-coded so i wanted to have an assertion to check if the value generated is a valid guid format. Closest I got was: https://stackoverflow.com/questions/7905929/how-to-test-valid-uuid-guid

This thread is trying to answer question "Is there a way to assert if a value is a guid/uuid?"

2 replies

function validateUUID(uuid) { const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/; return uuidRegex.test(uuid); } function validateGUID(guid) { const guidRegex = /^[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}$/; return guidRegex.test(guid); }

is this correct use then?


Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.