开发者

Problem with email validation in Opera and Chrome

I use simple js email validation like:

 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 { 
          开发者_JS百科$("#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


In this test:

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

What is it that you mean by checking the email candidate string against 0? Did you mean:

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

perhaps? (The test is redundant anyway, as your regex insists on non-empty strings.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜