Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

RegularExpressionValidator canadian postal code help

im using the following expression to validate a canadian postal code

^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$

which works fine with the following formats:

M5E 1J2 OR M5E1J2

But i also want it to include recognize the following format M5E-1J2, what could i include to make this happen

Thanks!

Alex Zaff
alex@cleanalliance.com
Environmental Services (http://www.cleanalliance.com)
[486 byte] By [clean] at [2007-11-11 8:08:49]
# 1 Re: RegularExpressionValidator canadian postal code help
Somone else's response in another forums resolved this, here's the solution:

See that \space in the middle?

Replace it with [ \-]{0,1} There is a space followed by \-.

See this page for more on regexes: http://regexlib.com/CheatSheet.aspx

------------------------
-- Peter Blum
Creator of Professional Validation And More, Peter's Date Package, and Visual Input Security
www.PeterBlum.com
clean at 2007-11-11 23:13:26 >