RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

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: The rating for this expression. Clark Hay
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

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})?$


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials