function checkEmail() { var error_string = ""; var the_email = window.document.email_form.toemail.value; var from_email = window.document.email_form.fromemail.value; var format=/^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/; if(the_email.search(format) == -1){ error_string += "The To email address is invalid.\n"; } if(from_email.search(format) == -1){ error_string += "The From email address is invalid.\n"; } if (error_string == "") { return true; } else { error_string = "We found the following errors in your form: \n" + error_string; alert(error_string); return false; } }