US ZIP Code Validation Regex
Validate US ZIP codes in both 5-digit (12345) and ZIP+4 (12345-6789) formats.
Pattern & Test String
About This Pattern
Pattern: ^\d{5}(-\d{4})?$
Flags: g
Results
Enter a regex pattern to see the results here.
Frequently Asked Questions
Does this work for both 5-digit and ZIP+4 formats?
Yes, this pattern matches both. The (-\d{4})? makes the +4 extension optional.
Does it validate if the ZIP code actually exists?
No, regex only validates format. To verify actual ZIP codes, use a USPS address validation API.
Can I make the ZIP+4 format required?
Yes, remove the ? to require it: ^\d{5}-\d{4}$
Practical Examples
Address Form Validation
Validate ZIP code input in shipping or billing forms.
Location-Based Services
Validate ZIP codes for store locators or service areas.
Mailing List Segmentation
Extract and validate ZIP codes for geographic targeting.
Common Issues & Solutions
This accepts any 5 digits. Invalid codes like 00000 or 99999 will match. Check against a valid ZIP code database for verification.
Some systems store ZIP codes with leading zeros. Ensure your database doesn't strip them.
For Canadian postal codes, use a different pattern: ^[A-Z]\d[A-Z] ?\d[A-Z]\d$