Title |
Test
Find
Pattern Title
|
Expression |
^(([0-9]{5})*-([0-9]{4}))|([0-9]{5})$ |
Description |
Accepts valid US Postal Code - either 5 digit, or extended |
Matches |
99999 | 99999-2222 | 999992222 |
Non-Matches |
99999- | 99999-222 |
Author |
Rating:
Clark Hay
|
Source |
|
Your Rating |
|
Title: This one matches the description though...
Name: Jeremy
Date: 10/16/2006 6:08:36 PM
Comment:
Randal, this one will actually match the full description of what Clark was looking for in the first place.
^\d{5}-?\d{4}$
Title: Bad "*" in there
Name: Randal L. Schwartz
Date: 6/23/2005 5:51:11 AM
Comment:
The "*" in there means this also matches "-1234" and "1234512345". 0 or more groups of 0-5 digits.
A much simper regex is:
^\d{5}(-\d{4})?$