Can anyone tell me what is wrong with this code?
<html>
<head>
<title>JavaScript Error Checking</title>
<script language = "javascript">
function checkWholeForm(theForm)
{
why = "";
why += checkFname(theForm.fname.v
alue);
why += checkLname(theForm.lname.v
alue);
why += checkEmail(theForm.email.v
alue);
why += checkPhone(theForm.phone.v
alue);
if (why != "")
{
alert(why);
return false;
}
return true;
}
function checkFname(string)
{
var error = "";
if (!(string.search(/(a-z) +/))) || (!(string.search(/(A-Z) + /)))
error = "First name is wrong";
}
function checkLname(string)
{
var error = "";
if (!(string.search(/(a-z) +/))) || (!(string.search(/(A-Z) + /)))
error = "Last name is wrong";
}
function checkEmail(string)
{
var error = "";
var emailFilter = /^.+@.+\..{2,3}$/;
if (!(emailFilter.test(string
)))
{
error = "Email is wrong";
}
}
function checkPhone(string)
{
var error = "";
error = "Phone number is wrong";
}
</script>
</head>
<body>
<font size = +1><b>This is a sample registration form.</b></font><br>
<font size = "-1">Please fill in all fields and click Register</font>
<form name = "theForm">
<img src = "user.gif"><br>
<font size = "-1">Pleae fill out the fields below</font><br>
<img src = "fname.gif">
<input type = "text" name = "fname" size = "23"><br>
<img src = "lname.gif">
<input type = "text" name = "lname" size = "23"><br>
<img src = "email.gif">
<input type = "text" name = "email" size = "23"><br>
<img src = "phone.gif">
<input type = "text" name = "phone" size = "23"><br>
<font size = "-2">Must be in the form (555)555-5555</font><br><b
r>
<input type = "button" value = "Verify" size = "23" onClick = "checkWholeForm(this)"><br
>
</form>
</body>
</html>
I got most of my information from
http://www.oreillynet.com/pub/a/javascript/2001/08/10/form_valid.html. Not too sure why its not working.
Thanks
Start Free Trial