I have a form with an email field.
As part of the validation I would like to exclude certain domains ( eg gmail,yahoo etc )
I have found the following function which should search for substrings which I believe is a good choice to search my email strings in: jquery/javascript check string for multiple substrings:
function isSubStringPresent(str){
for(var i = 1; i < arguments.length; i++){
if(str.indexOf(arguments[i]) > -1){
return true;
}
}
return false;
}
isSubStringPresent('myemail', 'gmail', 'yahoo', ...)
I am confused on how to integrate this function with the jquery validator plugin.
Please see below:
I have the following following below my form:
$(document).ready(function(){
$.validator.addMethod(
"wrong_domain",
THE isSubStringPresent FUNCTION SHOULD BE INSERTED HERE SOMEHOW...
},
'Not an acceptable email' );
$.validator.classRuleSettings.wrong_domain = { wrong_domain: true};
$('#registration-form').validate({
rules: {
FirstName: {
required: true,
},
Email: {
required: true,
email: true,
wrong_domain: true
},
Can someone show me how to do this?