最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to validate email after the '.(dot)' while submitting form using Jquery Plugin - Stack Overflow

programmeradmin0浏览0评论

I'm trying to validate a form having an email address whose prop is set to 'true' as shown:

$( "#myform" ).validate({
  rules: {
   field: {
    required: true,
     email: true
    }
  }
});

I checked out the jquery plugin / and i see that the email address gets verified only until the '@' symbol(example in the above link). I'm making a email validation script that basically just checks for plete emailaddress including the 'dot' at the end. any ideas how to achieve this??

/

I'm trying to validate a form having an email address whose prop is set to 'true' as shown:

$( "#myform" ).validate({
  rules: {
   field: {
    required: true,
     email: true
    }
  }
});

I checked out the jquery plugin http://jqueryvalidation/email-method/ and i see that the email address gets verified only until the '@' symbol(example in the above link). I'm making a email validation script that basically just checks for plete emailaddress including the 'dot' at the end. any ideas how to achieve this??

http://jsfiddle/dbnkahee/1/

Share Improve this question asked Sep 24, 2015 at 4:26 user1234user1234 3,1596 gold badges57 silver badges117 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can add jQuery.validator.addMethod with your Regex try this:-

jQuery.validator.addMethod("emailfull", function(value, element) {
 return this.optional(element) || /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i.test(value);
}, "Please enter valid email address!");

And then use it as:-

$( "#myform" ).validate({
  rules: {
  field: {
   required: true,
   emailfull: true
 }
 }
});

RegEx by aSeptik see this answer

Demo

Other RegEx

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论