Email Validation with Regular Expression C#
Below is the Regular Expression to Validate Email Address
Sample Code:
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="http://www.w3.org/1999/xhtml"> <head> <title>Regular Expression to validate Email Address</title> </head> <body> <form id="form1" runat="server"> <table> <tr> <td><b>Enter Email:</b></td> <td> <asp:TextBox ID="txtEmail" runat="server" /> </td> </tr> <tr> <td></td> <td><asp:Button ID="btnValidate" runat="server" Text="Validate Email" onclick="btnValidate_Click" /> </td> </tr> </table> <asp:label id="lblerrormsg" runat="server" style=" font-weight:bold; " /> </form> </body> </html> |
No comments:
Post a Comment