Follow in Twitter & Facebook

Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools

Sunday, August 5, 2012

Regular Expressions validation control Asp.Net

In this article we will disucss about Regular Expressions validation control which is very much useful to validate email address, phone number etc. You can also check about Validation controls in here.

Regular expression will be helpful to validate email id, phone number, zip code etc. In this example we will validate an email address for a textbox.

HTML Code:
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        <br />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="txtEmail" ErrorMessage="Please enter a valid email id"

Here the main properties are:
ControlToValidate - This is id of the control which we will validate, here the textbox of Id- txtEmail.

Error Message: This is the error message that will appear to user if invalid data enters.

Validation express: This is the validation expression, here is to validate email address:

So need to write validation expression for different conditions like:
Password validation that will be menimum 4 characters but not greater than 20 characters: "\w{4,10}"

0 on: "Regular Expressions validation control Asp.Net"