Validate E-mail Address with RegularExpressionValidator in Asp.Net

Leave a Comment

In this tutorial, we have study how to work with regular expressions to validate input field with RegularExpressionValidator.

In below example, the control checks that the text input in the text box is a valid e-mail address.
<div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="E-mail is not in a valid format" ValidationExpression=".*@.{2,}\..{2,}"></asp:RegularExpressionValidator>
    </div>
The expression .*@.{2,}\..{2,} specifies that the string that it is validating must begin with a number of characters (.*) and must contain an @ character, at least two more characters (the domain name), a period  (escaped as \.), and, finally, at least two more characters for the domain extension.

Read More - Commonly Used Regular Expressions for Validation Control in Asp.Net

0 comments:

Post a Comment