Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript regex for canadian postal code [duplicate]

Possible Duplicate:
Canada postal code validation

I need javascript regex for validating Canadian postal/zip code. Canada's Postal Code format is 'A1A 1X1' or 'a1a1x1'. However it doesn't include the letters D, F, I, O, Q, or U.I found few here but those were in C#.

like image 420
DarknessBeginsHere Avatar asked Oct 07 '12 22:10

DarknessBeginsHere


1 Answers

function checkPostal(postal) {
    var regex = new RegExp(/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]( )?\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i);
    if (regex.test(postal.value))
        return true;
    else return false;
}
like image 157
DarknessBeginsHere Avatar answered Sep 23 '22 04:09

DarknessBeginsHere