Leo67
10-09-2003, 11:02 AM
Hi,
I am VERY new to javascript. I am currently trying to add an input field into a form that performs the following validation.
1. if the user enters six characters the form validates the code to show as X2X2X2 (CDN Postal Code). All letters are capitalized automatically and a message pops up showing telling the user that they have to enter the Postal Code as X2X2X2 format.
2. if the user enters 5 characters (US Zip Code) the characters all need to be numbers.
The current error message I am receiving is the following: 'return' statement outside the function. I have played with the code so much at this point that no matter what I change I am getting numerous error messages. Please help!!
_________________________________________________________
<SCRIPT LANGUAGE="JavaScript">
function CheckPostalZip (input) {
s = this.form1.PostalZip.value;
strlen = this.form1.PostalZip.length;
filteredValues = " !@$#%^&*/,-";
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}
input.value = returnString.toUpperCase();
}
if (strlen == 6)
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(input.charAt(0,2,4)) < 0) {return false;}
if ('0123456789'.indexOf(input.charAt(1,3,5)) < 0) {return false;}
ELSE
if (strlen==5)
if ('0123456789'.indexOf(input.charAt(0,1,2,3,4)) < 0) {return false;}
return true;
}
</script>
</HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" BGCOLOR="#FFFFFF"><br><br><br><br>
<form name="form1" method="get" onSubmit="return CheckPostalZip()" action="PostalZipTest.asp">
<table cellpadding="0" cellspacing="0" width="200" align="center">
<tr><td height="23" nowrap>POSTAL/ZIP CODE :</td><td height="23"><input type="text" name="PostalZip" size="6" maxlength="6"></td></tr>
</table>
</form>
I am VERY new to javascript. I am currently trying to add an input field into a form that performs the following validation.
1. if the user enters six characters the form validates the code to show as X2X2X2 (CDN Postal Code). All letters are capitalized automatically and a message pops up showing telling the user that they have to enter the Postal Code as X2X2X2 format.
2. if the user enters 5 characters (US Zip Code) the characters all need to be numbers.
The current error message I am receiving is the following: 'return' statement outside the function. I have played with the code so much at this point that no matter what I change I am getting numerous error messages. Please help!!
_________________________________________________________
<SCRIPT LANGUAGE="JavaScript">
function CheckPostalZip (input) {
s = this.form1.PostalZip.value;
strlen = this.form1.PostalZip.length;
filteredValues = " !@$#%^&*/,-";
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}
input.value = returnString.toUpperCase();
}
if (strlen == 6)
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(input.charAt(0,2,4)) < 0) {return false;}
if ('0123456789'.indexOf(input.charAt(1,3,5)) < 0) {return false;}
ELSE
if (strlen==5)
if ('0123456789'.indexOf(input.charAt(0,1,2,3,4)) < 0) {return false;}
return true;
}
</script>
</HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" BGCOLOR="#FFFFFF"><br><br><br><br>
<form name="form1" method="get" onSubmit="return CheckPostalZip()" action="PostalZipTest.asp">
<table cellpadding="0" cellspacing="0" width="200" align="center">
<tr><td height="23" nowrap>POSTAL/ZIP CODE :</td><td height="23"><input type="text" name="PostalZip" size="6" maxlength="6"></td></tr>
</table>
</form>