Created
February 20, 2014 17:17
-
-
Save nery/9118763 to your computer and use it in GitHub Desktop.
Canadian postal code validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Slightly strict regex check for validly formatted Canadian postal code | |
http://jsfiddle.net/7mBFf/ | |
*/ | |
var postal = new RegExp(/^\s*[a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z](\s)?\d[a-ceghj-npr-tv-z]\d\s*$/i); | |
console.log(postal.test('m6k1s4')); // returns true | |
console.log(postal.test('M6K1S4')); // returns true | |
console.log(postal.test('90210')); // returns false | |
console.log(postal.test('d6k1s4')); // returns false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment