function checkData() {

   var pattern = /\s*\w+@[^\.]+\.[^\.]+(\.[^\.])*\s*/;
   legalChars = "~0123456789.-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@+";
   errorMsg = "";
    
    with (document.mainform) {

    if (realname.value.length < 2)  errorMsg += "\nYour name is required for processing this form";
    if (day_phone_prefix.value.length < 3)  errorMsg += "\nA valid area code is required for processing this form";
    if (day_phone_suffix.value.length < 7)  errorMsg += "\nA valid phone number is required for processing this form";


  if (FromEmail.value.length < 7)
    errorMsg += "\nE-Mail address must be at least 7 characters";
  //Validate Email against pattern match
  if (FromEmail.value != "") {
      if(!pattern.test(FromEmail.value)) {
      errorMsg += "\nInvalid E-Mail Address."
      }
  }
  //This enhances the previous EMail check. This checks for legal values and returns illegal values
  if (FromEmail.value != "" && FromEmail.value.length > 1) {
      for(x=0; x < FromEmail.value.length; x++) {
    if (legalChars.indexOf(FromEmail.value.substring(x,x+1)) < 0)
        errorMsg += "\n" + "Illegal character '"+FromEmail.value.substring(x,x+1)+"' at position " +(x+1)+ " in E-Mail Address.";
      }
  }
//    }

  //FINAL CHECK FOR ERROR MESSAGES
  if (errorMsg.length > 0) {
    errorMsg = "The following errors must be corrected before submitting this form: \n" + errorMsg
    alert (errorMsg);
    return false;
  }

   }  //end WITH

return true;
}

