override jquery validate plugin email address validation

前端 未结 4 1158
离开以前
离开以前 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:33

    // Add Custom Email Validation
    jQuery.validator.addMethod('customemail', function (emailaddr, element) {
          emailaddr = emailaddr.replace(/\s+/g, '');
          return this.optional(element) || 
          emailaddr.match(/^\b[A-Z0-9._%-]+@@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i);
     });
    

提交回复
热议问题