Hi!
I'm new to regexp and javascript so bear with me.
I have the following regular expression in Javascript:
commPattern = new RegExp("^\d\.\d{1,3}$" ;
to check for a format such as 0.01, 9.231, etc. however it doesn't work and returns null.
I tried doing an alert( commPattern ) and it displayed /^d.d{1,3}$/
I tried adding an extra "\" since I was out of ideas:
commPattern = new RegExp("^\\d\\.\\d{1,3}$" ;
and it worked! doing an alert( commPattern ) displays the regexp correctly: /^\d\.\d{1,3}$/.
This confuses me a lot since I've read in all the tutorials that "/" enables us to use stuff like "\d" for numeric characters or "/." to match ".". I'm thinking from what I've read, that I don't need to add the extra "\". I even tried my search string in and it was working fine.
Any help would be appreciated
Environment:
Windows 2000
IE 5.50.4807.2300 SP2- downloaded from I think, since MS stopped providing a 5.5 download.
I'm new to regexp and javascript so bear with me.
I have the following regular expression in Javascript:
commPattern = new RegExp("^\d\.\d{1,3}$" ;
to check for a format such as 0.01, 9.231, etc. however it doesn't work and returns null.
I tried doing an alert( commPattern ) and it displayed /^d.d{1,3}$/
I tried adding an extra "\" since I was out of ideas:
commPattern = new RegExp("^\\d\\.\\d{1,3}$" ;
and it worked! doing an alert( commPattern ) displays the regexp correctly: /^\d\.\d{1,3}$/.
This confuses me a lot since I've read in all the tutorials that "/" enables us to use stuff like "\d" for numeric characters or "/." to match ".". I'm thinking from what I've read, that I don't need to add the extra "\". I even tried my search string in and it was working fine.
Any help would be appreciated
Environment:
Windows 2000
IE 5.50.4807.2300 SP2- downloaded from I think, since MS stopped providing a 5.5 download.