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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Validate US Postal Code
Expression
^(?!00000)(?<zip>(?<zip5>\d{5})(?:[ -](?=\d))?(?<zip4>\d{4})?)$
Description
Validate US zip codes. Matches all zip codes of exactly 5 digits except 00000. Optionally, matches zip5+zip4 where zip5 is exactly 5 digits, zip4 is exactly 4 digits, and zip5 and zip4 are, optionally, separated by a single space or hyphen. Captures zip5 and zip4 to named groups to facilitate program manipulation.
Matches
12345 | 123456789 | 12345-6789
Non-Matches
12345- | 00000 | 00000-6789
Author Rating: Not yet rated. Jerry Schmersahl
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: Pattern failure
Name: Hardryv
Date: 9/5/2006 6:24:56 PM
Comment:
parsing "^(?!00000)(?\d{5})(?:(?:[- ]?)(?\d{4}))?$" - Unrecognized grouping construct I had high hopes that this pattern would not only lead me to a solution, but also teach me something. For some reason it failed when tested. Can you please fix it or advise me what switches you ran it with to test it please?


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