How can I exclude/block yahoo.com domain during jquery form validation?

Hi there,

And welcome to the forums.

I’m unaware of an “exclude” method, but it would be quite easy to code this up by hand.

This is what I would do:

$(document).ready(function(){
  // Custom validation rule
  $.validator.addMethod("checkDomain", function(value, element) {
    var evilDomains = ["yahoo", "gmail", "aol", "hotmail"];
    var domainEntered = value.replace(/.*@(.*)\\..*/, "$1");
    var isAcceptableDomain = true;
    
    if($.inArray(domainEntered, evilDomains) >= 0){
      isAcceptableDomain = false;
    }
      return this.optional(element) || (isAcceptableDomain);
  }, "Please use a sensible mail address");    
  
 $("#webform").validate({
    errorPlacement: function(error, element) {
      error.appendTo( element.parents("div.field:first").find("div.clear:first") );                                                        
    },
    onfocusout: false,
    onkeyup: false,
    onclick: false,
    debug: false,
    rules: {
      email : { checkDomain: true }
    } // rules
  }); // validate
}); // function

Hopefully the code is quite straight forward, but if you have any questions, just let me know.