Skip to content

Instantly share code, notes, and snippets.

@gwhitelaw
Created April 30, 2013 11:44
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 gwhitelaw/5488195 to your computer and use it in GitHub Desktop.
Save gwhitelaw/5488195 to your computer and use it in GitHub Desktop.
Validate UUID
validateUuid = (text) -> (text || "").match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/)
validateUuid(null) # returns null
validateUuid("") # returns null
validateUuid("not-a-valid-uuid") # returns null
validateUuid("73963155-27db-48ad-abee-7afa2dd14af1") # returns regex match array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment