Regex for ZIP Code and Postal Code Validation
Quick Answer: US ZIP: ^\d{5}(-\d{4})?$. UK postcode: ^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$. Canadian: ^[A-Z]\d[A-Z]\s?\d[A-Z]\d$. Each country has its own postal code format. Paste your regex to test against sample codes.
FAQ
Does US ZIP code regex validate the ZIP exists?
No. The regex only checks format (5 digits or 5+4). ZIP code 99999 passes regex but does not exist. Use USPS API for existence validation.
How do I validate postal codes for multiple countries?
Use a library like postal-codes-js or google-libphonenumber. Each country has unique format rules making a single regex impractical.