Sponsored Ad

Thursday, June 24, 2010

How to Validate Zip Code using RegularExpressionValidator in ASP.NET

RegularExpressionValidator is very useful control to validate any custom logic. For example in this sample code, 5 digit zip code validation is implemented using asp.net.

So whenever user enters the input other than 5 digits. It prompts for error.

 

How to Validate Zip Code using RegularExpressionValidator in ASP.NET

How to Validate Zip Code using RegularExpressionValidator in ASP.NET

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<body>
    <form id="Form1" runat="server">
        <h4>
            Check for 5 digit zip code</h4>
        <br />
        Enter a zip code of 5 digits:
        <asp:TextBox ID="txtRegularExp" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" Text="Validate" runat="server" />
        <br />
        <br />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtRegularExp"
            ValidationExpression="\d{5}" ErrorMessage="Please enter 5 digit zip code" runat="server" />
    </form>
</body>
</html>

0 comments:

Post a Comment

Sponsored Ad

More Related Articles

Website Update

Followers