Skip to content

Instantly share code, notes, and snippets.

@aztack
Created July 20, 2023 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aztack/518fce9989b9f7c9a7f7d63970d1464b to your computer and use it in GitHub Desktop.
Save aztack/518fce9989b9f7c9a7f7d63970d1464b to your computer and use it in GitHub Desktop.
Tell whether given string is a uuid
const uuidRegex = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(--[0-9a-f]{5})?$/i;
function isUuid(str: string) {
if (typeof str !== 'string') return false;
return uuidRegex.test(str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment