I'm having difficulty putting together a regular expression for a numeric input of 0-15.
I have tried this expression:
^([9]{1,1}|[0-1][0-5])$
<asp:FilteredTextBoxExtender ID="TMPFiltered" runat="server" FilterMode="ValidChars"
FilterType="Custom" ValidChars^([9]{1,1}|[0-1][0-5])$" TargetControlID="txtTMP" />
however it is allowing for higher maximums than 15. Where is my syntax incorrect? Any help is appreciated, thanks.
Try this:
^([0]?[1-9]|1[0-5])$
or try this if you dont want to match like "07"
^([1-9]|1[0-5])$
Regex is not the right solution for this, you should just try to convert the string to an int and if that succeeds make sure the result is in your desired range.
That being said, here is a regex that should work:
^(1[0-5]?|[2-9])$
The primary issue with your current regex is that the anchors are only applied to the left side of the alternation, so you will match strings that match [0-1][0-5] anywhere in the regex. You also don't have any way in your current regex to just match numbers from 2 to 8.
Example: http://www.rubular.com/r/HUNZZymzFW
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With