Created
August 5, 2016 18:47
-
-
Save pimbrouwers/43ffc30f9e9cf2b19480a98fffe8ecac to your computer and use it in GitHub Desktop.
Canadian Postal Code & US Zip Code Regex
This file contains 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
var re = /^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$|^\d{5}(?:[-\s]\d{4})?$/i; | |
var str = 'm5v3e6'; | |
var m; | |
if ((m = re.exec(str)) !== null) { | |
if (m.index === re.lastIndex) { | |
re.lastIndex++; | |
} | |
// View your result using the m-variable. | |
// eg m[0] etc. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment