Home > ASP.Net, Javascript > Validate Email Address

Validate Email Address


Hi

try this example using Javascript

<asp:TextBox ID="txtEMail" onblur="validate_CDetails1()" size="25" CssClass="Form_Text"

runat="server"></asp:TextBox>

<span id="Span3" class="error">
   <div id="div_errorem1" style="text-align: left"></div>
</span>

javascript code

function validate_CDetails1()
{
    var oField = document.frm_registration.txtEMail.value;
    var em = document.frm_registration.txtEMail.value;
    var reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

    if(oField == "")
    {
        document.getElementById('div_errorem1').innerHTML ="Please Enter EMail.";
    }
    else if(reg.test(em) == false)
    {
        document.getElementById('div_errorem1').innerHTML ="Please Re Enter a Valid EMail.";
    }
    else
    {
        document.getElementById('div_errorem1').innerHTML ="";
    }
}

The above code will work

Good Luck

Advertisements
Categories: ASP.Net, Javascript Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: