// Checks US 5 digit and 9 digit zip codes as well as Canadian postal code (capital insensitive)
function checkPostal(postalCode) {
let pattern = new RegExp("(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)", "i");
return pattern.test(postalCode);
}
Posted: March 20, 2023
Return to the snippets listing