A valid 5 digit zip code : Regular Expression Validator « Validation by Control « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » Validation by Control » Regular Expression Validator 
A valid 5 digit zip code

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Submit" />&nbsp;
        <asp:RegularExpressionValidator 
        ControlToValidate="txtValue" 
        ErrorMessage="RegularExpressionValidator"
        SetFocusOnError=true
        ID="RegularExpressionValidator1" runat="server" 
        ValidationExpression="\d{5}(-\d{4})?">Please enter a valid digit zip code</asp:RegularExpressionValidator>
    
    </div>
    </form>
</body>
</html>

 
Related examples in the same category
1.Try validation based on Regular Expression in C#
2.Using a RegularExpressionValidator Control to Prevent the Entry of a Special Character (VB.net)
3.Regular expression validator: ^\d{5}$|^\d{5}-\d{4}$ (VB.net)
4.Validate input of US SSN
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.