Validate Email with RegularExpression validation using JavaScript

Last Reply 8 months ago By dharmendr

Posted 8 months ago

My requirement am using RegularExpressionValidator for email

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

Posted 8 months ago Modified on 8 months 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();" />