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
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:
I deliberately left case sensitivity on, demanding that UUID string passed in lowercase. However, if you think otherwise, obviously we can add
imodifier to a regex (I would rather not).Thank you