Saturday, 1 March 2014

How To Validate Email with Regular Expression C#

Email Validation with Regular Expression C#

Below is the Regular Expression to Validate Email Address 
bool isEmail = Regex.IsMatch(txtEmail.Text.Trim(), @"\A(?:[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)\Z");

Sample Code:

 <html xmlns="">
<title>Regular Expression to validate Email Address</title>
<form id="form1" runat="server">
<td><b>Enter Email:</b></td>
<asp:TextBox ID="txtEmail" runat="server" />
<td><asp:Button ID="btnValidate" runat="server" Text="Validate Email"
onclick="btnValidate_Click" /> </td>
<asp:label id="lblerrormsg" runat="server" style=" font-weight:bold; " />

No comments:

Post a Comment