// JavaScript Document function validateFormOnSubmit(theForm) { var reason = ""; //alert("Valid information: " + theForm.agreed.checked); var ok = theForm.agreed.checked; reason += validateEmpty(theForm.fname, 'First name'); reason += validateEmpty(theForm.surname, 'Surname'); reason += validateEmail(theForm.email); //reason += validateCheckbox(theForm.agreed, 'Select information entered is genuine'); if (!ok) { reason += " - Select information entered is genuine\n"; } //alert("Valid information: " + ok); //reason += checkCheckbox (theForm, 'agreed', 1, 'Select information entered is genuine'); if (reason != "") { alert("Please correct the following:\n\n" + reason); return false; } return true; } function validateEmpty(fld, msg) { var error = ""; if (fld.value.length == 0) { fld.style.background = 'Yellow'; error = " - " + msg + "\n"; } else { fld.style.background = 'White'; } return error; } function validateCheckbox(fld, msg) { var error = ""; alert("Validating information..." + document.bookingform.agreed[0].checked); if (fld.checked == false) { error = " - " + msg + "\n"; } return error; } /* function checkCheckbox (f,name,require, msg) { var checked = 0, e, i = 0; var error=""; while (e = f.elements[i++]) {if (e.type == 'checkbox' && e.className == name && e.checked) checked++} if (checked < require) { error = " - " msg + "\n"; } return error; } */ function trim(s) { return s.replace(/^\s+|\s+$/, ''); } function validateEmail(fld) { var error=""; var tfld = trim(fld.value); // value of field with whitespace trimmed off var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ; var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ; if (fld.value == "") { fld.style.background = 'Yellow'; error = " - Email\n"; } else if (!emailFilter.test(tfld)) { //test email for illegal characters fld.style.background = 'Yellow'; //Please enter a valid email address error = " - Email\n"; } else if (fld.value.match(illegalChars)) { fld.style.background = 'Yellow'; error = " - Email\n"; } else { fld.style.background = 'White'; } return error; } function validateVerify(fld) { var error=""; if (fld.value != "L85Za") { fld.style.background = 'Yellow'; error = " - Verification code\n"; } else { fld.style.background = 'White'; } return error; } function validatePhone(fld) { var error = ""; var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, ''); if(fld != ""){ if (isNaN(parseInt(stripped))) { error = " - Phone\n"; fld.style.background = 'Yellow'; } else if (!(stripped.length == 10)) { //The phone number is the wrong length. Make sure you included an area code error = " - Phone (Please include a valid area code)\n"; fld.style.background = 'Yellow'; } else { fld.style.background = 'White'; } return error; } }