Reputation: 21
I am trying to get my regex string right but I don't seem to get it working as it should.
I have a numeric field that should have 5 digits.
The digits can start only with 04xxx
and 5xxxx
This string is not covering it completly:
/[05][0-9][0-9][0-9][0-9]/
it forces to start with 0 or 5 followed by 4 digits, but it allows for example 012345
Any ideas?
Upvotes: 2
Views: 36
Reputation:
This looks more like a validation -
^(?=04|5)\d{5}$
Expanded:
^ # BOS
(?= 04 | 5 ) # Lookahead, starts with '04' or '5'
\d{5} # Match 5 digits
$ # EOS
Upvotes: 1