Wednesday, 11 December 2013

How to validate Email Address in ASP.NET?

To validate Email ID in ASP.NET, set the following RegularExpressionValidator properties:

ID Email_Validator
ControlToValidate Email_ID
ErrorMessage Please enter the valid Email Address.
ValidationExpression ^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$

Code Snippet:
<asp:RegularExpressionValidator ID="Email_Validator" runat="server" ControlToValidate="Email_ID" ErrorMessage="Please enter the valid Email Address" ValidationExpression="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"></asp:RegularExpressionValidator>

(Note: Email_ID is a TextBox ID in which email id would be entered by user).

No comments:

Post a Comment