javascript - Integrating custom function and rule using JQuery validator plugin -


i have form email field.
part of validation exclude domains ( eg gmail,yahoo etc )

i have found following function should search substrings believe choice search email strings in: jquery/javascript check string multiple substrings:

function issubstringpresent(str){     for(var = 1; < arguments.length; i++){         if(str.indexof(arguments[i]) > -1){             return true;         }     }         return false; }      issubstringpresent('myemail', 'gmail', 'yahoo', ...) 

i confused on how integrate function jquery validator plugin.

please see below:

i have following following below form:

$(document).ready(function(){      $.validator.addmethod(                     "wrong_domain",                     issubstringpresent function should inserted here somehow...                                         },                     'not 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 show me how this?

try using apply pass in multiple excluded domains validation function:

var excludes = ['myemail', 'gmail', 'yahoo']; $.validator.addmethod(     "wrong_domain",     function(value, element) {          // take shallow copy of excludes         var myarguments = excludes.slice(0);         // add value front of arguments         myarguments.unshift(value);         // use myarguments arguments array issubstringpresent         return !issubstringpresent.apply(this, myarguments);     },     'not acceptable email' ); 

here's example fiddle. validate input after every keypress event.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -