Reputation: 117
I have this regex that test for an input with max length of 5. My problem is I want to exclude the single digit of 2. If string contains only number "2", it should fail. How do I exclude number 2 in this regex? /^([a-zA-Z,\d]){1,5}$/
13425 - Match
03277 - Match
2 - Fail.
Upvotes: 2
Views: 3295
Reputation: 305
I was having the same issu, i need to match all number with five degit except those :
^\\d{5}$
?!(23030|22060|21037|21050)
-->The final pattern : (?!((^4789[3-9]$)|23030|22060|21037|21050))^\\d{5}$
Upvotes: -1
Reputation: 338148
A negative look-ahead assertion can do this for you
/^(?!2$)([a-zA-Z,\d]){1,5}$/
Upvotes: 4