I am trying to perform a regular expression that validates the following format:
- there will only be numbers separated by commas or hyphen
- there may be ranges of numbers (separated by hyphens)
- the numbers must go from 1 to 31
- that the value of the second part is greater than that of the first (this is still more complex, but if it is very difficult I will discard it)
Example of strings I would consider valid:
4.31.2-22.8
29.1-10.2-12.9
Example of invalid strings:
4.31.2-22.8,
29.1-10,-2-12-.9
29.1-50.2-12.32
The regular expression I have so far is the following:
((([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]|1[0-9]|2[0-9]|3[0-1]))?))*)
At the moment this expression handles the issue of hyphens and commas well, but I can't get it to handle the numbers from 10 to 31 well and the issue of the range that the second value is greater than the first I can't think of how to solve it. suggestion?