I'm trying to make a regular expression that validates the following format:
- there will only be numbers separated by , or -
- there may be ranges of numbers (separated by -)
- the numbers should go from 1 to 31
- the value of the second part is greater than the first one in a range (this is more complex, but if it is very difficult I will discard it)
Example that I would consider valid:
4,31,2-22,8
29,1-10,2-12,9
Example that I would consider invalid:
4,31,2-22,8,
29,1-10,-2-12-,9
29,1-50,12-2,32
The regular expression that I have so far is the following:
(((1[0-9]|2[0-9]|3[0-1]|[1-9])(\-(1[0-9]|2[0-9]|3[0-1]|[1-9]))?)(\,((1[0-9]|2[0-9]|3[0-1]|[1-9])(\-(1[0-9]|2[0-9]|3[0-1]|[1-9]))?))*)
At the moment this expression takes me well the "-" and ",", and that the numbers go from 1 to 31. The problem of the rank that the second value is greater than the first I have no idea of how to solve it. Any suggestions?
39as well, and does not fulfil the condition for ranges.