Skip to content

Instantly share code, notes, and snippets.

@Torthu
Created December 4, 2020 11:42
Show Gist options
  • Save Torthu/d2484ba06d415a52d4f3c5bed0181bd3 to your computer and use it in GitHub Desktop.
Save Torthu/d2484ba06d415a52d4f3c5bed0181bd3 to your computer and use it in GitHub Desktop.
Quick UUIDv4 regex/type guard
type UUID = string;
function isUuid(uuid: string): uuid is UUID {
return (
uuid.match(/^[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}$/)
?.length > 0
);
}
export default UUID;
export isUuid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment