function validate_email() { // valid, error message, email error, email both v = true, e_msg, e_e = false, e_b = false; st_n = getById("r_student_name"); st_e = getById("re_student_email"); pr_n = getById("r_prof_name"); pr_e = getById("re_prof_email"); var e_ = getById("mailformheader"); if (st_n.value == "") { v = false; e_msg = "Please fill out the form completely."; } if (st_e.value == "") { v = false; e_msg = "Please fill out the form completely."; } if (pr_n.value == "") { v = false; e_msg = "Please fill out the form completely."; } if (pr_e.value == "") { v = false; e_msg = "Please fill out the form completely."; } var rxp = new RegExp("^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$"); var st_match = rxp.exec(st_e.value), pr_match = rxp.exec(pr_e.value); if (st_match == null) { v = false; } if (pr_match == null) { v = false; if (st_match == null) { e_b = true; } } if(!v) { if(e_e) { if (e_b) { e_msg = "\""+st_e.value+"\" and \""+pr_e.value+"\" are not valid email addresses."; } else { if (st_match == null) { e_msg = "\""+st_e.value+"\" is not a valid email address."; } if (pr_match == null) { e_msg = "\""+pr_e.value+"\" is not a valid email address."; } } e_.innerHTML = e_msg; } else { e_.innerHTML = e_msg; } return false; } else { return true; } }