EMail Validation using jQuery with Regular Expression | How to do EMail validation using jQuery

Home » Uncategorized » EMail Validation using jQuery with Regular Expression | How to do EMail validation using jQuery
Uncategorized No Comments

 EMail Validation using jQuery with Regular Expression | How to do EMail validation using jQuery

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <title></title>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnSubmit').click(function () {
                var inputEmail = $("#txtEmail").val();
                var emailRegularExpression = /^(^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*)@[0-9a-zA-Z]+([_.-]?[0-9a-zA-Z])*.[a-zA-Z]{2,4})+$/;

                if (!emailRegularExpression.test(inputEmail)) {
                    $('#ErrorMessage').html('Invalid Email Address');
                }
            });
        });
    </script>
</head>
<body>
    <input type="text" id="txtEmail" />
    <input type="submit" id="btnSubmit" />
    <div id='ErrorMessage' style="color:red;"></div>
</body>
</html>

LEAVE A COMMENT