Wasiq Muhammad
Wasiq Muhammad

Reputation: 3118

Apply maximum and minimum limit in Regex

Here is my username regex, i want to apply limit that allow only 3 characters minimum and 15 characters maximum.

 /^[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)*$/

This Regex Validate below criteria

Upvotes: 3

Views: 488

Answers (1)

vks
vks

Reputation: 67978

^(?=.{3,15}$)[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)*$

Just add a lookahead.See demo.

https://regex101.com/r/uE6jQ1/12

Upvotes: 6

Related Questions