Form validation

Type your e-mail address:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript">
<!--
// Adapted from //http://www.oreillynet.com/pub/a/javascript/2001/08/10/form_valid.html
// and
//http://www.thesitewizard.com/archive/validation.shtml
function checkEmail (strng) {
var error="";
if (strng == "") {
error = "You didn't enter an email address.\n";
return (error);
}

var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) {
error = "Please enter a full or valid email address like 'joe@somewhere.com'\n";
return (error);
}
else {
//test email for illegal characters
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
error = "The email address contains illegal characters.\n";
}
}
return error;
}

function checkmyform() {
var anyerror = "";
anyerror += checkEmail(document.myform.email.value);
if (anyerror != "") {
alert(anyerror);
document.myform.email.focus();
return false;
}
//What follows is only executed if "anyerror" was empty.
alert('You entered: '+document.myform.email.value+' which looks like a valid e-mail address. ');
alert("Normally you'd now get whisked to some script");
//Change this to return true if you'd actually like to have the form
//submit to the script at this point
return false;
}
//-->
</script>
</head>

 

<body>
<form name="myform" method="post" action="eventualScriptAddress.php"
onSubmit="return checkmyform();"
>
Type your e-mail address:
<input type="text" name="email">
<input type="submit">
</form>