Validate Email with RegularExpression validation using JavaScript

Last Reply one year ago By dharmendr

Posted one year ago

My requirement am using RegularExpressionValidator for email

textbox  this need to fire on button onclientclick function using javascript.

Posted one year ago Modified on one year ago

Hi amar,

Refer below sample.

<html xmlns="">
    <script type="text/javascript">
        function ValidateEmail() {
            var regx = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
            var email = document.getElementById("txtEmail").value;
            if (!regx.test(email)) {
                alert("Invalid email address.");
            else {
                alert("Email address is valid.");
    <input name="txtEmail" type="text" id="txtEmail" />
    <input type="button" value="Validate" onclick="ValidateEmail();" />


You can change the html control with the below asp controls.

<asp:TextBox ID="txtEmail" runat="server" />
<asp:Button Text="Validate" runat="server" OnClientClick="return ValidateEmail();" />