EasyRegex Logo
EasyRegex
New

Match American Zip Code

Javascript

Regular Expression

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

Explanation

This regex pattern matches American zip codes. It starts with a word boundary \b, followed by 5 digits \d{5}. It then optionally matches a hyphen and 4 digits (?:-\d{4}) before ending with another word boundary \b.

Javascript

Example Usage

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

Similar Regular Expressions