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
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?