EasyRegex Logo
EasyRegex
Nouveau

Match American Zip Code

Javascript

Expression Régulière

\b\d{5}(?:-\d{4})?\b
Copier
Avez-vous des Retours ?

Explication

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

Exemple d'Utilisation

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

Expressions Régulières Similaires