function validate() { // validate var forename, surname, tel, email, doi, loi, incident, injuries; forename = document.getElementById("Forename").value; surname = document.getElementById("Surname").value; tel = document.getElementById("Telephone").value; email = document.getElementById("Email_Address").value; doi = document.getElementById("Date_of_Incident").value; loi = document.getElementById("Location_of_Incident").value; incident = document.getElementById("Describe_The_Incident").value; injuries = document.getElementById("Describe_Your_Injuries").value; // Validate form var valForm = new Array(); if (forename == "") { valForm[valForm.length] = '\r\n Forename is a required field'; } if (surname == "") { valForm[valForm.length] = '\r\n Surname is a required field'; } if (tel == "") { valForm[valForm.length] = '\r\n Telephone is a required field'; } if (email == "") { valForm[valForm.length] = '\r\n E-mail Address is a required field'; } else if (ValidateItem('email', email)) { valForm[valForm.length] = '\r\n Please enter a valid e-mail address'; } if (doi == "") { valForm[valForm.length] = '\r\n Please provide us with the date of the incident'; } if (loi == "") { valForm[valForm.length] = '\r\n Please provide us with the location of the incident'; } if (incident == "") { valForm[valForm.length] = '\r\n Please provide us with a description of the incident'; } if (injuries == "") { valForm[valForm.length] = '\r\n Please provide us with a description of your injuries '; } // Check for invalid entries if (valForm.length > 0) { alert('Some errors occurred in your submission: \r\n' + valForm.toString()); return false; } else { return true; } } /* Validations */ function ValidateItem(ftype, fvalue) { switch(ftype) { case "email": var objRegExp = /^.+@[^\.].*\.[a-z]{2,}$/; //check for format return objRegExp.test(fvalue); } }