JQuery Regular Expression Email

I am developing a script, and now I am at a dead end. I tried many different Regex from Google and did not work, this is my code:

$(document).ready(function() {
    var email_check = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/;
    num = 0;
    $('#email').focus(function() {
        $('#email_check').show();
        $(this).keyup(function() {
            error = 0;
            var email = $('#email').val();
            num = num+1;
            if(!email_check.test(email)) {
                error = 1;
            }
            if(error == 0) {
                $('#email_check').html('O'+num+email+error);
            }else if(error == 1) {
                $('#email_check').html('X'+num+email+error);
            }
        });
    });
});

Any help is great, thanks!

+3
source share
2 answers

Set flag (i) case insensitive:

var email_check = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i;
+12
source

You can skip the regex entry and use the jQuery validation plugin for this task. Here is an example of an email address verification here .

+2
source

All Articles