简体   繁体   English

Opera和Chrome中的电子邮件验证问题

[英]Problem with email validation in Opera and Chrome

I use simple js email validation like: 我使用简单的js电子邮件验证,例如:

 function validation(email) {
     var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
     return reg.test(email);
 }


 function check(){
   if ($("#subemail").hasClass("bad")) {
       var subemail = $("#subemail").val();
       if((subemail!=0)&&validation(subemail)) {
          $("#subemail").css('background','transparent').css('color','#3b3b3b');
          $('.arrow').css('visibility','hidden');
       }
       else { 
          $("#subemail").css('background','url(img/red.png)').css('color','white');
          $('.arrow').css('visibility','visible');
       }
    }
 }

everything works fine with Firefox but while doing it in Chrome or Opera it always return false 一切都可以在Firefox上正常运行,但是在Chrome或Opera中运行时始终返回false

In this test: 在此测试中:

if((subemail!=0)&&validation(subemail)) {

What is it that you mean by checking the email candidate string against 0? 通过检查电子邮件候选字符串是否为0是什么意思? Did you mean: 你的意思是:

if ((subemail != '') && validation(subemail)) {

perhaps? 也许? (The test is redundant anyway, as your regex insists on non-empty strings.) (无论如何,该测试都是多余的,因为您的正则表达式坚持使用非空字符串。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM