如何在使用Jquery插件提交表单时验证'。(dot)'后的电子邮件 [英] How to validate email after the '.(dot)' while submitting form using Jquery Plugin

查看:93
本文介绍了如何在使用Jquery插件提交表单时验证'。(dot)'后的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证一个包含电子邮件地址的表单,其道具的设置为'true',如下所示:

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
    }
  }
});

我检查了jquery插件 http://jqueryvalidation.org/email-method/ 我看到电子邮件地址仅在@符号(上面链接中的示例)之前得到验证。我正在制作一个电子邮件验证脚本,基本上只检查完整的电子邮件地址,包括最后的点。任何想法如何实现这个??

I checked out the jquery plugin http://jqueryvalidation.org/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 complete emailaddress including the 'dot' at the end. any ideas how to achieve this??

http:/ /jsfiddle.net/dbnkahee/1/

推荐答案

您可以添加 jQuery.validator.addMethod 试试这个: -

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
 }
 }
});

aSeptik的RegEx查看此答案

演示

其他RegEx

这篇关于如何在使用Jquery插件提交表单时验证'。(dot)'后的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆