This ought to move you forward:-
Code:
<script type = "text/javascript">
function validate() {
if (document.mailpage.contact_name.value=="") {
alert("Name not entered");
return false
}
if (document.mailpage.contact_address.value=="") {
alert("Address not entered");
return false
}
if (document.mailpage.contact_otherinfo.value=="") {
alert("Operational Details / Other Information was not entered");
return false
}
var f = 0;
var em = document.mailpage.contact_email.value;
if (em != "") { // if em contains a value
if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(em))) {
alert("Invalid Email address - please re-enter");
document.mailpage.contact_email.value = "";
document.mailpage.contact_email.focus();
return false;
}
else {f++} // an email address has been entered
}
var ph = document.mailpage.contact_phone.value;
ph = ph.replace(/[^0-9\-/,""); //strip non-numeric characters except hyphen
if (ph != "") { // if ph contains a value after stripping
if (ph.length < 10) {
alert ("Phone number not valid - please re-enter");
document.mailpage.contact_phone.value = "";
document.mailpage.contact_phone.value.focus();
return false
}
else {f++} // a phone number has been entered
}
if (f==0) {
alert ("You must enter either your email address or your phone number, or both");
return false;
}
else {return true}
}
</script>
Note that validation of the type
if document.mailpage.contact_name.value=="") { is barely worthy of the name, and is virtually worthless, as even a single space or a ? will return false (i.e. pass the validation). You should
a) strip leading and trailing spaces
b) remove inappropriate characters (a name can only be a-z hyphen apostrophe space)
c) check for a minimum length (say at least 3 alpha characters)
"In the beginner's mind there are many possibilities, but in the expert's mind there are few” - Shunryu Suzuki (Japanese Zen priest, ?-1971)