override jquery validate plugin email address validation

前端 未结 4 1159
离开以前
离开以前 2020-11-27 19:31

I find that jQuery validation plugin regex to be insufficient for my requirement. It accepts any email address xxx@hotmail.x as a valid email address whereas I want to be ab

4条回答
  •  有刺的猬
    2020-11-27 19:35

    Try this!

       jQuery.validator.addMethod("customEmail", function(value, element) {
                 return this.optional(element) || /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i.test(value);
                }, "Please enter valid email address!");
    
            $(form).validate({
                 rules: {
                     email:{
                         required:true,
                         customEmail:true
                     }
                 }
            });
    

提交回复
热议问题