MY bLOG

Monday, 16 December 2013

how to validate email address using java script

I would like to explain about email id validation using java script

code in .aspx page:

<head runat="server">
    <title>java script validation for Email Id</title>
    <script type="text/javascript">
        function checkEmail() {
    //here the function called the submit button.
            var email = document.getElementById('txtEmail');
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
//here we will assign the validation for email address
            if (!filter.test(email.value)) {
                alert('Please provide a valid email address');
//alert message show weather the email is valid or not
                email.focus;
                return false;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <input type='text' id='txtEmail'/>
        <input type='submit' name='submit' onclick='checkEmail();'/>
    </div>
    </form>
</body>
 i hope you understand this email validation using java script.

No comments:

Post a Comment