SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Oct 15, 2007, 20:03 #1
- Join Date
- Nov 2005
- Location
- Midwest
- Posts
- 777
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Regular Expression Function Expected
Hello
I am having an issue getting this regular expression to work in IE 7. This code works perfect in FireFox & Netscape, but it does not work in IE7. The error IE 7 gives me is:
Function Expected
Below is the code. Does anyone know why I am getting this error?
Code:<html> <head> <script language="JavaScript"> function test() { //-- Regular Expression to validate the entered Zip Code regZip = new RegExp(/(^\d{5}$)/); if( regZip( document.getElementById("zipCode").value ) ) { alert("Thank you for entering a valid Zip Code"); } else { alert("Entered Zip Code is not valid."); } } </script> </head> <body> <input type="Text" id="zipCode" /> <input type="Button" value="validate" onClick="test();" /> </body> </html>
-
Oct 15, 2007, 22:03 #2
- Join Date
- Apr 2006
- Posts
- 802
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
regZip= /(^\d{5}(\-\d{4})?$)/;
if( regZip.test(document.getElementById("zipCode").value ) ) {
alert("Thank you for entering a valid Zip Code");
}
else alert("Entered Zip Code is not valid.");
Not a great idea to call the function 'test'....
-
Oct 16, 2007, 07:48 #3
- Join Date
- Nov 2005
- Location
- Midwest
- Posts
- 777
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you for pointing out that I needed to call the function
regZip.test( )
As for the name, this is just a proof of concept but I would agree with you, test() would not be a good name for production code.
Thank you again for the help.
Bookmarks