PDA

View Full Version : javascript regular Expressions



ganu
05-12-2009, 07:20 AM
Hai,

I have one problem that is i need the canada postal code validations using regular expressions the postal code is of 7digits including white space a0E T5R means it is combination of digits and alphabets and a space after 3 digits.using javascript
please help me to getride from this problem.
Thanks & Regards
G.anuradha

forum_amnesiac
05-12-2009, 08:54 AM
Not positive but try validating against this

/^\s*[abceghj-nprstvxyABCEGHJ-NPRSTVXY]\d[a-zA-Z](\s)?\d[a-zA-Z]\d\s*$/

I've tested this but it fails against your example.

My investigations show that Canadian postcodes are formatted a9A 9A9, this code works against that.

I have also not allowed 'w' or 'z' as the first letter because they are not used yet