Regular Expression To Match A Number Range In Javascript
I'm having problem with JavaScript regular expressions. I want to match real numbers form 1 to 5. Precission is in two digits. My code is but it doesnt work. function validate_pro
Solution 1:
You need to "anchor" your regexp with ^
and $
to match the beginning and end of the string, respectively:
var pattern = /^([1-4]\.[0-9][0-9]|5\.00)$/;
You also need to escape the .
because it's a special character in regexps, and there's no need to call new RegExp
if the regexp is already in /.../
synax.
Post a Comment for "Regular Expression To Match A Number Range In Javascript"