how to remove error text from the email format checker code?

Posted by rdesai on Stack Overflow See other posts from Stack Overflow or by rdesai
Published on 2012-04-15T17:21:40Z Indexed on 2012/04/15 17:28 UTC
Read the original article Hit count: 150

Filed under:
|

I have been writing a code for validating forms using javascript/jquery. Following is a code snippet for checking email format. The problem is when I enter invalid email, it recognizes it, but when I go back to this field and enter correct email, the error text still stays even though I have used the 'else' part. How do I remove the error text in this case?

if(e1.value!=''){
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.signupForm.email1.value.search(emailRegEx) == -1) {
        $("#err_email1").html("Please enter valid email address.");
    }
    status=0;         
}
else{
    $("#err_email1").html("");
    status=1;
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery