Reputation: 739
I want to validate a string to meet the following patterns:
00;0 (disallow)
00;00 (disallow)
01;123 (disallow)
00;1
00; (disallow)
00;000000 (disallow)
00;1234567890123 (disallow)
00;123456789012
00;10
00;01
00;00001
00;00100
00;0202020
00;1000000
00;00100100
In general, the string should be ^00;\d{1,12}$
but how to eliminate unnecessary lines in the example above and resolve the necessary in one regex expression?
Thanks.
Upvotes: 1
Views: 134
Reputation: 785186
You may use this regex:
^00;(?!0+$)\d{1,12}$
RegEx Details:
^00;
: Match 00;
at start of line(?!0+$)
: Negative lookahead to fail the match if we have all zeroes\d{1,12}$
: Match 1 to 12 characters of any digit before endUpvotes: 1