daryl
daryl

Reputation: 15197

Regex character limit

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

Answers (1)

Regexident
Regexident

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

Related Questions