Skip to content

Better way to validate UUID strings #1

@maxsatula

Description

@maxsatula

I would like to offer a better (more strict, paranoid) way to validate UUID strings, rather than just length check after hyphens are stripped (how can we be sure the hyphens were at the right places?)
I never used TypeScript, so my example is in pure JavaScript:

new RegExp( '^' + [8, 4, 4, 4, 12].map( l => `[0-9a-f]{${l}}` ).join('-') + '$' ).test(uuid)

I deliberately left case sensitivity on, demanding that UUID string passed in lowercase. However, if you think otherwise, obviously we can add i modifier to a regex (I would rather not).

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions