例如,电子邮件地址未完全验证.我有一个电子邮件字段,我从jQuery验证插件验证它.当我把一些像“abbcss”时,它说电子邮件无效.然后我把“abbcss @ g”错误消失了,你可以看到电子邮件仍无效.为了更好地理解我在这里放了一个小提琴.
$(document).ready(function(e) { $('#email').keyup(function(){ $('#checkform').validate(); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <link href="//getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/> <script src="//cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.js"></script> <form id="checkform"> <input id="email" type="email" name="email"> </form> <hr> <p>Try to put first "abcc" and click outside field </p> <p>then try to put "abcc@gmail" and click outside field </p> <p>it will consider it a valid email but actually it is not.</p>
关于这个问题的任何帮助都会很合适.
解决方法
您可以使用jquery验证插件
add method验证电子邮件
jQuery.validator.addMethod("validate_email",function(value,element) { if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)) { return true; } else { return false; } },"Please enter a valid Email."); $('#checkform').validate({ rules: { email: { validate_email: true },} });