PDA

View Full Version : My js validation form isn't validating



ad3cycles
01-15-2008, 03:04 AM
my form validation isn't validating...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">

<!-- saved from url=(0066)http://www.nvcc.edu/home/drodgers/ITP140/resources/Assignment4.htm -->
<HTML lang=en dir=ltr xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>assignment_4</TITLE>
<script language="JavaScript" type="text/javascript" src="validate.js"></script>
</HEAD>
<BODY>

<DIV
style="PADDING-RIGHT: 1em; PADDING-LEFT: 1em; BORDER-LEFT-COLOR: saddlebrown; BORDER-BOTTOM-COLOR: saddlebrown; PADDING-BOTTOM: 1em; WIDTH: 90%; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: saddlebrown; PADDING-TOP: 1em; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BACKGROUND-COLOR: linen; BORDER-RIGHT-COLOR: saddlebrown; BORDER-BOTTOM-STYLE: solid">
<H2>Validate a Zip Code for Canada</H2>
<FORM action="">
<P><INPUT id=ca_zip name=ca_zip>
<INPUT type="button" value="Check It!" onClick="isValidZip (zip,country)"></P></FORM></DIV>
<P>&nbsp;</P>
<DIV
style="PADDING-RIGHT: 1em; PADDING-LEFT: 1em; BORDER-LEFT-COLOR: saddlebrown; BORDER-BOTTOM-COLOR: saddlebrown; PADDING-BOTTOM: 1em; WIDTH: 90%; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: saddlebrown; PADDING-TOP: 1em; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BACKGROUND-COLOR: linen; BORDER-RIGHT-COLOR: saddlebrown; BORDER-BOTTOM-STYLE: solid">

<H2>Validate a Zip Code for <SPAN
style="FONT-WEIGHT: bold; COLOR: Blue; FONT-STYLE: italic">[US, France, and Monaco]</SPAN></H2>
<FORM action="">
<P><INPUT id=check_zip name=check_zip>
<INPUT type="button" value="Check It!" onClick="isValidZip(zip,country)"></P></FORM></DIV>
<P>&nbsp;</P>
<DIV
style="PADDING-RIGHT: 1em; PADDING-LEFT: 1em; BORDER-LEFT-COLOR: saddlebrown; BORDER-BOTTOM-COLOR: saddlebrown; PADDING-BOTTOM: 1em; WIDTH: 90%; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: saddlebrown; PADDING-TOP: 1em; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BACKGROUND-COLOR: linen; BORDER-RIGHT-COLOR: saddlebrown; BORDER-BOTTOM-STYLE: solid">
<H2>Validate an Email Address</H2>
<FORM action="">
<P><INPUT id="check_email" size="40" name="check_email"> <INPUT type="button" value="Check It!" onClick="isValidEmail()"></P></FORM></DIV>
<P>&nbsp;</P>
<DIV
style="PADDING-RIGHT: 1em; PADDING-LEFT: 1em; BORDER-LEFT-COLOR: saddlebrown; BORDER-BOTTOM-COLOR: saddlebrown; PADDING-BOTTOM: 1em; WIDTH: 90%; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: saddlebrown; PADDING-TOP: 1em; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BACKGROUND-COLOR: linen; BORDER-RIGHT-COLOR: saddlebrown; BORDER-BOTTOM-STYLE: solid">
<H2>Format Phone Number</H2>

<FORM action="">
<P><INPUT id="phone_in" size="40" name="phone_in">
<input name="button" type="button" value="Format It!" onClick="isPhoneNum()">
</P>
<P>Your phone number formatted as <SPAN
style="FONT-WEIGHT: bold; COLOR: blue">[Sample phone format: Example
(703) 456-7890]</SPAN></P>
<P><INPUT id="phone_out" size="40" name="phone_out"></P></FORM></DIV></BODY></HTML>



and here is my external jscript


// JavaScript Document

function isValidZip (zip,country){
if(!zip) return false;
if(!country) format = 'US';
switch(country){
case'US': zipRegExp = /^\d{5}$|^\d{5}-\d{4}$/; break;
case'CA': zipRegExp = /^[A-Z]\d[A-Z] \d[A-Z]\d$/; break;
case'FR': zipRegExp = /^\d{5}$/; break;
case'Monaco':zipRegExp = /^(MC-)\d{5}$/; break;
}
return true;
}


function isValidEmail(string){
emailRegExp =
(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/);

if(!emailRegExp.test(string)){
alert("Email Is Not Valid");
return false;
}
return true;
}


function isPhoneNum(s)
{
isPhoneNumRegExp = (/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
if (!isPhoneNumRegExp.test(s)) {
alert("Phone Number Must Be Entered As: (555) 555-1234");
return false;
}
return true;
}

thanks in advance for the help,
david