I’m somewhat new to regular expressions and am writing validation for a quantity field where regular expressions need to be used.
How can I match all numbers greater than or equal to 50?
I tried
[5-9][0-9]+
but that only matches 50-99. Is there a simple way to match all possible numbers greater than 49? (only integers are used)
The fact that the first digit has to be in the range
5-9only applies in case of two digits. So, check for that in the case of 2 digits, and allow any more digits directly:This regexp has beginning/ending anchors to make sure you’re checking all digits, and the string actually represents a number. The
|means “or”, so either[5-9]\dor any number with 3 or more digits.\dis simply a shortcut for[0-9].Edit: To disallow numbers like
001:This forces the first digit to be not a zero in the case of 3 or more digits.