//Function to check form is filled in correctly before submitting
function CheckForm () {
//Intialise variables
var errorMsg = "";
var errorMsgLong = "";
from=eval("document.emailform.fm.value");
document.emailform.cc.value=from;
//Check for a name
if(!validate_email(document.emailform.fm.value)){
errorMsg += "\nFROM\t- Please enter a valid e-mail address";
}
//Check for a subject
if (document.emailform.re.value == ""){
errorMsg += "\nSUBJECT\t- Please enter a heading for your comments and inquiries";
}
//Check for comments
if (document.emailform.msg.value == ""){
errorMsg += "\nMESSAGE\t- Please enter your comments and inquiries";
}
//If there is aproblem with the form then display an error
if ((errorMsg != "") || (errorMsgLong != "")){
msg = "Please enter values in the NAME, SUBJECT, and MESSAGE fields\n";
msg += "so I can respond to you more effectively. Thank you.\n";
msg += "______________________________________________________\n";
errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
return false;
}
return true;
}
// function to validate email address
function validate_email(email_address)
{
// pattern is a regular expression, that fits any valid email address;
var pattern = new RegExp(/([\w]{1,}[\w\-\.]*@[\A-Za-z0-9]{1}[\A-Za-z0-9\-]*[\.][\A-Za-z0-9\-\.]{2,})/);
pattern.exec(email_address);
// condition checks if regular expression fetches full email address, and that last part of email address (the TLD) contains at least two characters;
if(RegExp.$1==email_address&&email_address.split(".")[email_address.split(".").length-1].length>1) return true;
return false;
}