views:

28

answers:

1

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 { 
          $("#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

A: 

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.)

Pointy