jQuery validate email with regex (regular expression)

If you want to validate email with regex (regular expression) in jQuery, you can use the following code snippet:

jQuery( document ).ready(function() {
    var email = 'test@loremipsum.com';
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!regex.test(email)) {
        alert('Invalid Email Id');
    } else {
        alert('Valid Email Id');
    }
});

Leave a Reply