Hello, I'm trying to validate the form, but each time I try to do so, all fields return invalid. I've tested my regular expressions with various online testers and they seem to work fine, am I perhaps using it in the wrong way? Or maybe a problem with my functions?:-/
Any Help would be very much appreciated.
Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nicholas Gingerella Assignment 7</title>
</head>
<body>
<script language="javascript" type="text/javascript">
function validate_email()
{
if (document.FORM.email.value==/^\w+@\w+\.com|net|edu$/)
{;return true;}
else if (document.FORM.email.value==/^\w+\.\w+@\w+\.com|net|edu$/)
{;return true;}
else
{alert("Not a valid email address");return false;}
}
function validate_fullname()
{
if (document.FORM.fullname.value==/^[a-zA-Z]+\s[a-zA-Z]+$/)
{;return true;}
else
{alert("Invalid name format.");return false;}
}
function validate_zipcode()
{
if (document.FORM.zipcode.value==/^[0-9]{5}$/|/^[0-9]{5}-[0-9]{4}$/)
{;return true;}
else
{alert("Invalid zipcode format.");return false;}
}
function validate_phonenumber()
{
if (document.FORM.phone.value==/^[0-9]{3}-[0-9]{4}$/|/^[0-9]{3}-[0-9]{5}-[0-9]{4}$/)
{;return true;}
else
{alert("Not a valid phone number.");return false;}
}
function validate_form()
{
if (validate_fullname()==false|validate_email()==false|validate_zipcode()==false|validate_phonenumber()==false)
{return false;}
else
{return true;}
}
</script>
<form name="FORM" onsubmit="return validate_form()">
Enter the requested information below:
<br />
First and last name:
<input type="text" name="fullname" />
<br />
Email Address:
<input type="text" name="email" />
<br />
Zip Code:
<input type="text" name="zipcode" />
<br />
Phone number:
<input type="text" name="phone" />
<br />
<input type="submit" value="Submit"/>
</form>
</body>
</html>