Checks whether a value is a valid US postal code, in either ZIP (12345) or ZIP+4 (12345-6789) form. Surrounding whitespace is ignored.
12345
12345-6789
Optional
The postal code to check.
True when the value is a well-formed US postal code.
isValidUsPostalCode("33132"); // trueisValidUsPostalCode("33132-3204"); // trueisValidUsPostalCode("H2K 3H4"); // false Copy
isValidUsPostalCode("33132"); // trueisValidUsPostalCode("33132-3204"); // trueisValidUsPostalCode("H2K 3H4"); // false
Checks whether a value is a valid US postal code, in either ZIP (
12345) or ZIP+4 (12345-6789) form. Surrounding whitespace is ignored.