Enable User to Validate Canada and US Zip Code

This small code will help you to validate US and Canada zip code. It means this regular expression validator control will allow user to enter only US and Canada zipcode in format like 5 digit numeric(US) or Canada format like (R2G 1T9).

<asp:RegularExpressionValidator runat="server" ID="regZipCode" ControlToValidate="txtRegZipCode"

ValidationExpression="^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z] \d[A-Z]\d$" Display="dynamic"

ErrorMessage="Zip Code correct format For US 5 digits like 85123,for Canada a format like R2G 1T9">

</asp:RegularExpressionValidator>

 


Similar Articles