I'm trying to get someone to use a specific email domain of @mail.fhsu.edu
. Here is my Validation code.
function validateFHSUEmail(inputField, helpText) {
if (inputField.value.length == 0) {
if (helpText != null) {
helpText.innerHTML = "Please Enter a Value";
}
return false;
} else {
var reg = /^[a-z.]+@mail.fhsu.edu$/;
if (!reg.test(inputField)) {
if (helpText != null) {
helpText.innerHTML = "Please Enter FHSU Email";
}
Am I calling it wrong or what because no matter what it returns false.
You're testing the variable "inputField", which apparently is a reference to a DOM element. You want inputField.value
in the test.
edit Note the comment wherein it's pointed out that your regex should use \\.
for the periods in the domain name.
如果您想要有效的电子邮件和特定域名,请试用此正则表达式:
/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@domain.com$/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.