Reputation: 55
As the title says I'm looking for a regex to provide the following. Using Asp.net regular expression valiator.
I need to validate a range of x-y.
The numbers for x and y can't start with 0.
The numbers for x and y can be 1 digit to 6 digits in length.
No other characters other than numbers and one dash between them allowed.
Value of x can't be a lower value than y or equal to y. (probably have to check this another way)
Here are examples of what should pass and fail:
0-252 > fail
1-252 > pass
9823-10000 > pass
10-3 > fail
12345 > fail
498 8987 > fail
0023-002343 > fail
1234567-1234567 > fail
123456-123457 > pass
2-10-233 > fail
Thanks!
Upvotes: 0
Views: 268
Reputation: 213351
Value of x can't be a lower value than y or equal to y. (probably have to check this another way)
Exactly. You should better validate this without regex. For the rest of the condition, you can use this regex:
^[1-9][0-9]{0,5}-[1-9][0-9]{0,5}$
Upvotes: 1