javascriptjqueryajax-forms

Email check with jQuery doesn't work


I tried to make Ajax form and tried to make email verification there. I found this solution http://jsfiddle.net/EFfCa/

but can't turn it on in my script:

<script> 
    $('#joinForm').ajaxForm(function() {
        var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
        var name = $("input[name=name]")
        var email = $("input[name=email]")
        if(name.val()==''||email.val()=='') {
            $(".notify").show();
            $(".notify p").text('empty');
        } else if(testEmail.test(email.value)) {
            $(".notify").show();
            $(".notify p").text('email is wrong');      
        } else {
            $(".notify").show();
            $(".notify p").text('good');    
        }
    }); 
</script>

The form always passed verification even email is wrong. Verification for empty fields works good...


Solution

  • The following line else if(testEmail.test(email.value)) will return true if the email is correct.

    In your logic that's where the email is wrong could that be the problem?