I have a regular expression as such:
var pat = new RegExp("[0-9]{1}\.[0-9]{1}");
I use jQuery to get a number from a textbox as such:
var theValue = $(item).val();
I’ve been entering numbers and testing the regex with this line:
alert(pat.test(theValue));
If I enter the number .111 it passes. This should not be the case as the first digit has to be 0-9 followed by a period and then followed by another digit 0-9. I can’t see what I am doing wrong.
To use in a string, you need to escape the
\in order for the backslash character to appear.A more concise, and perhaps more reliable form would be this:
Assuming the pattern should match a single number followed by a period followed by another single number.