EasyRegex Logo
EasyRegex
New

Match US Zip Codes in JavaScript

javascript

Regular Expression

\b\d{5}(?:-\d{4})?\b
Copy
Do you have Feedback?

Explanation

This regex pattern will match US zip codes. It looks for 5 digits optionally followed by a hyphen and 4 more digits. The \b ensures that the zip code is a whole word.

javascript

Example Usage

const regex = /\b\d{5}(?:-\d{4})?\b/; 
const zipCode = '12345-6789'; 
console.log(zipCode.match(regex));
Copy
Test the expression

Similar Regular Expressions