Form Validation II
Continuing on from the first part of the tutorial, we are going to continue through the list of form elements in the order we setup. Next we work on the email address.
else if(document.getElementById(“email”).value==” ||
(document.getElementById(“email”).value!=” &&
!emailfilter.test(document.getElementById(“email”).value))){
document.getElementById(“error_msg”).childNodes[0].data=
‘Please enter a valid e-mail address.’;
document.getElementById(“error_msg”).style.display = “block”;
document.getElementById(“email”).focus();
return false;
}
Notice how we handle the email value checking first to see if it is empty to trigger an error and then using the logical operator OR (denoted as ||), we then look at another statement. In that statement we use the logical operator AND (denoted as &&) to trigger an error, and if both the email filed is not empty and the emailfilter.test is not valid then we do what is in between the curly brackets again. The contents are the same as what we described in the first statement.
