Can someone give me a regular expression for a number to be between 1 and 5, single digit
e.g. input has to be a number between 1 and 5 , 55 or 23 would not match
Try using anchors:
/^[1-5]$/
Explanation:
^ Start of line/string. [1-5] A digit between 1 and 5. $ End of line/string.
Would it not be simpler to check it as a number (ie if(x>=1 && x<=5) or something similar) rather than using a regex?
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