Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?!0{3})\d{5}(?:-?\d{4})?$
/
gm

Description

This Regex is for US Zip Code like 5 digits (12345), or like 9 digits with no spaces (123456789), or like 10 digits with a hyphen if it has the 9 numbers (12345-6789) and also Starting 3 continuous characters MUST NOT zeros(0).

Submitted by anonymous - 6 years ago