Validating TimeUuid using JavaScript (Node.js) -
i validate uuid string make sure it's valid time uuid (i.e. test check if string time uuid).
for example: request comes in id so, string: 54d890dc-40a5-4686-8d7e-095e3934d99e (this uuid v4), there way test whether uuid time uuid (v1) or not (uuid v4)?
you can use regexp :
for example
const index = [ // uuid v1: /^[0-9a-f]{8}-[0-9a-f]{4}-[1][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i // uuid v2: /^[0-9a-f]{8}-[0-9a-f]{4}-[2][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i // uuid v3: /^[0-9a-f]{8}-[0-9a-f]{4}-[3][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i // uuid v4: /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i //uuid v5: /^[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i ].findindex(x => x.test(stringtotest)); console.log(index === -1 ? 'unknown uuid' : `uuid version ${index + 1}`); here uuid regexp
Comments
Post a Comment