ai / nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
https://zelark.github.io/nano-id-cc/
MIT License
24.33k stars 788 forks source link

Is there a way to validate if a string is nanoid? #405

Closed andreluizsgf closed 1 year ago

andreluizsgf commented 1 year ago

Hi, i want to use nanoid to generate some random ids but would like to check if a given string is nanoid and then query for it in a database. is this validation possible?

ai commented 1 year ago

I think /[\w_-]{21}/.test(id) should work

thevinitgupta commented 1 year ago

I was also looking for a validator. Is there a method added for this or does the above Regex work properly? @ai

ai commented 1 year ago

Yes, it should works.