Mega Code Archive

 
Categories / ASP.Net Tutorial / Validation
 

Validate Zip code

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Regular Expression Tester</title> </head> <body>     <form id="form1" runat="server">     <div>              <asp:Label ID="Label3"                     runat="server"                     Text="The Following Field (TextBox3) Must be a US Zip Code."></asp:Label><br />         <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>         <asp:RegularExpressionValidator ID="RegularExpressionValidator1"                                          runat="server"                                          ControlToValidate="TextBox3"                                         ErrorMessage="TextBox3 Must be a US Zip Code"                                          SetFocusOnError="True"                                          ValidationExpression="\d{5}(-\d{4})?">*</asp:RegularExpressionValidator><br />     </form> </body> </html>