468,470 Members | 1,735 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,470 developers. It's quick & easy.

ValidationExpression for zip/postal codes

I'm trying to get my zip code textbox to validate both US zip codes and Canadian Postal code formats. But I can't figure out the syntax. Can somebody help? Here is what I got:


Expand|Select|Wrap|Line Numbers
  1. <asp:regularexpressionvalidator id="rxZipCode" runat="server" ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Zip Code is invalid." ValidationExpression="\d{5}?" & "[A-Z]\\d[A-Z] \\d[A-Z]\\d">*</asp:regularexpressionvalidator>
Oct 5 '07 #1
5 3253
Plater
7,872 Expert 4TB
Good luck!
Postal codes are a mess
us can be just 5 or just 5 plus another 4 or just 5 plus 5, or more.
Some contain letters as well as numbers.
Oct 5 '07 #2
So ValidationExpression doesn't have an "or' operator?
Oct 5 '07 #3
Plater
7,872 Expert 4TB
So ValidationExpression doesn't have an "or' operator?
It should, I would just be surprised if you can find a big enough regex to cover postal codes.
Oct 5 '07 #4
Am I close with this? I put the | operator in there. It still only accepts US zips.

ValidationExpression="\d{5}?|[A-Z]\\d[A-Z] \\d[A-Z]\\d

The regex for Canadian Postals should be ok right? Is just ANA NAN, right?
Oct 5 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
This and This too

They give some regex's

cheers
Oct 5 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Andrew McLean | last post: by
4 posts views Thread by Dave \IT\ | last post: by
2 posts views Thread by Axel Foley | last post: by
1 post views Thread by Ronnie | last post: by
2 posts views Thread by Surfdog | last post: by
3 posts views Thread by skardian | last post: by
4 posts views Thread by racshah | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.