regex for canadian postal code

im trying to validate a canadian postal code using regex but i dont know that correct syntax..

can someone please help me ..thanks in advance

here is my code .. (postal code is letter number letter space number letter numberex R5Y 1E3)

String regex;

Pattern pattern;

Matcher matcher;

regex = "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]";

pattern = Pattern.compile(regex);

if(! pattern.matcher(param).matches())

[457 byte] By [Picard] at [2007-9-30 21:57:29]
# 1

[A-Z] isn't correct for the first character, for a start. I know for sure that "I" and "O" can't appear there, and I don't think they can appear in the other letter positions either. I also know that there aren't any postal codes starting with U or W or Y or Z, and there are probably others. I guess it depends how picky you want to get.

DrClap at 2007-7-7 3:25:16 > top of Java-index,Security,Event Handling...
# 2
I'll bet the rules for postal codes are listed somewhere on the Canadian postal service's web site.
paulcw at 2007-7-7 3:25:16 > top of Java-index,Security,Event Handling...
# 3
That's what I thought too, so I looked there. I found a PDF document for download about addressing standards, but I didn't download it. Here's a link that I did find, which looks practical enough for the OP's needs: http://mindprod.com/jgloss/postalcode.html
DrClap at 2007-7-7 3:25:16 > top of Java-index,Security,Event Handling...
# 4
http://www.forta.com/blog/index.cfm?mode=e&entry=996
edsonw at 2007-7-7 3:25:16 > top of Java-index,Security,Event Handling...
# 5
thanks for all replys this farI understand that there are limited values that belong in each place holder....but what i really need is the regex for it...
Picard at 2007-7-7 3:25:16 > top of Java-index,Security,Event Handling...
# 6
> but what i really need is the regex for it...Did you follow the links given to you?
camickr at 2007-7-7 3:25:16 > top of Java-index,Security,Event Handling...