Wednesday, April 24, 2013

How to validate Canada postal code by regular expression?

^[ABCEGHJKLMNPRSTVXY]\d[A-Z]\d[A-Z]\d$
Code example for ASP.NET webform  RegularExpression validator

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="*" ControlToValidate="TextBoxPostalCode" ValidationExpression="^[ABCEGHJKLMNPRSTVXY]\d[A-Z]\d[A-Z]\d$"></asp:RegularExpressionValidator>

Basic Concept
http://en.wikipedia.org/wiki/Regular_expression
Online Regular Expression tester
http://www.regular-expressions.info/javascriptexample.html

No comments:

Post a Comment