Created
March 29, 2020 15:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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