LogoReturn to Home RegEx
Integrations
All integrations
AWS API
AWS Lambda
DynamoDB
Oracle
Redshift
Snowflake
GraphQL
Supabase
Twilio
Azure Blob Storage
Slack
SendGrid
Generic HTTP API
AWS S3
Stripe
Microsoft SQL
Salesforce
PostgreSQL
MySQL
MongoDB
HubSpot
Google Sheets
Google BigQuery
Firebase
Airtable
Integrations
About UI Bakery
Log in
Request UI Bakery demo
RegEx library
Email regex
Phone number regex
IP address regex
Date regex
URL regex
Numbers only regex (digits only)
UUID regex
Regex match words
ZIP code regex
GUID regex
Password regex
HTML regex (regex remove html tags)
SSN regex
XML regex
Mac address regex
Street address regex

ZIP code regex

ZIP code (US postal code) regular expression can be used to verify if a given string contains a valid ZIP code or extract ZIP code from a string. Supports both 5-digit and 9-digit (ZIP+4) formats.

Discover UI Bakery – an intuitive visual internal tools builder. Try it now!
No items found.
JavaScript
Python
Java
C#
PHP

ZIP code regex

A regular expression to test a string against ZIP code format:

/^[0-9]{5}(?:-[0-9]{4})?$/
Test it!
/^[0-9]{5}(?:-[0-9]{4})?$/

True

False

Enter a text in the input above to see the result

Example code in Javascript:

var zipRegex = /^[0-9]{5}(?:-[0-9]{4})?$/;
// Validate zip code
zipRegex.test('80001'); // Returns true
zipRegex.test('80001-2222'); // Returns true
zipRegex.test('800010'); // Returns false

// Extract zip code from a string
var zipRegexG = /[0-9]{5}(?:-[0-9]{4})?/g;
'My zip code is 80001'.match(zipRegexG); // returns ['80001']
Test it!

True

False

Enter a text in the input above to see the result

Test it!

True

False

Enter a text in the input above to see the result

Notes on ZIP code validation and extraction

This ZIP code regex has several limitations:

  • It only works for US ZIP codes. If you need to support other countries, you might need to have a separate regular expression for each one of them and execute it based on the country provided.
  • It can not guarantee that ZIP code actually exists. For instance, 99999 is a correct format, but this ZIP code does not exist.
  • The extraction method can generate false-positive extraction if a string contains multiple numbers.

Create an internal tool with UI Bakery

Discover UI Bakery – an intuitive visual internal tools builder.

Try it now