Reputation: 15197
I'm using URI segments to match a form of ID and basically I want it to match strings of up to 5 characters only.
How do I go about regex for this? This is what I have so far but it doesn't work - which is why I'm here:
/([a-zA-Z0-9*]{5})(?![a-zA-Z0-9*])/
Upvotes: 0
Views: 3005
Reputation: 29552
Use either
/^[a-zA-Z0-9*]{1,5}$/
or
/^[a-zA-Z0-9*]{0,5}$/
if you want to also accept empty inputs.
^
and $
denote the start/end of the input string.
Upvotes: 4