Skip to content

Instantly share code, notes, and snippets.

@pimbrouwers
Created August 5, 2016 18:47
Show Gist options
  • Save pimbrouwers/43ffc30f9e9cf2b19480a98fffe8ecac to your computer and use it in GitHub Desktop.
Save pimbrouwers/43ffc30f9e9cf2b19480a98fffe8ecac to your computer and use it in GitHub Desktop.
Canadian Postal Code & US Zip Code Regex
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