EasyRegex Logo
EasyRegex
Nuovo

Match American Zip Code

Javascript

Espressione Regolare

\b\d{5}(?:-\d{4})?\b
Copia

Spiegazione

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

Esempio di Utilizzo

const regex = /\b\d{5}(?:-\d{4})?\b/; 
const zipCode = '12345'; 
console.log(regex.test(zipCode)); // Output: true
Copia
Prova l'espressione

Espressioni Regolari Simili