Skip to content

Instantly share code, notes, and snippets.

@cmanish049
Created March 29, 2020 15:40
Show Gist options
  • Save cmanish049/6b9c742e977dfe89573488ef689f4911 to your computer and use it in GitHub Desktop.
Save cmanish049/6b9c742e977dfe89573488ef689f4911 to your computer and use it in GitHub Desktop.
This simple snippet validates the email field to have email of specific domain
jQuery.validator.addMethod("domain_email", function(value, element, param) {
if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)) {
if (value.indexOf(param, value.length - param.length) !== -1) {
return true;
} else {
return false;
}
} else {
return false;
}
}, function(param) {
return "Email must end with the domain '" + param +"'"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment