Regex Zip Code 5 Digit, ZIP+4 Format: This format includes the 5-digit zip code followed by a hyphen and four additional digits (e. Matches 5 consecutive digits (may be used for a zip code). , 12345-6789). For example, Dublin zip codes are D01, D02, etc. 2. etc. The ZIP+4 extended US ZIP code Regular Expression Library provides a searchable database of regular expressions. *)?$` can be used to validate a US zip code. In 1983, an extended code was introduced named ZIP+4 ; it included the five digits of the ZIP Code, followed by a hyphen and four digits that Test String xxxxxxxxxx 1) US zip codes without the 4 digit extension (e. Contact Blog About Also, even if you were using search, you are not grabbing the group that includes the 5 digits that are guaranteed to be there. ### Regex Breakdown ``` ^ # Matches the start of the string \d {5} # Matches exactly five digits (?: # Starts a non $: Matches the end of the string. The third instance of a quantifier is {4}, indicating that four characters should be matched. Use regex for efficient validation in our comprehensive guide. , 12345–6789). The additional digits help to identify specific delivery points The regular expression `^\d {5} (?: [-\s\d]. Ctrl + Enter to check code. It looks for 5 digits optionally followed by a hyphen and 4 more digits. Regular expressions (regex) are a powerful tool for validating text patterns, and they provide an efficient way to check if a user-inputted ZIP code conforms to the 5-digit US format. NET, Rust. The regex should match 12345 and 12345-6789, but not 1234, 123456, 123456789, or 1234 ZIP codes range from 00501 to 99950, but this regex accepts any 5-digit combination for simplicity. Fill in the code to check if the text passed includes a possible U. Step-by-step guide included. This expression accepts either 5-digit strings or 5-digit strings followed by a hyphen and a 4-digit string. zip code, formatted as follows: exactly 5 digits, and sometimes, but not always, followed by a dash with 4 more Here is an example of a regular expression that can match a US zip code. Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/. Users can add, edit, rate, and test regular expressions. Copyright © 2009-2026 BucketSoft, LLC. The \b ensures that the zip code is a whole word. . , 12345) and ZIP+4 codes (e. The regular expression (regex) for matching a US ZIP Code can handle both the standard 5-digit format and the extended 9-digit format (ZIP+4) which includes a hyphen. Also, other cities Learn how to validate US zip codes on Linux using Bash or Python scripts. ) This article will delve into how to create a regex pattern that effectively validates US zip codes, including both the standard 5-digit format and the extended ZIP+4 format. Postal code validation made easy. Lastly, even if you were using search, starting your regex ZIP code regex Python ZIP code (US postal code) regular expression can be used to verify if a given string contains a valid ZIP code or extract ZIP code from a string. 0 comments so far. The second instance is also {5}. This blog will demystify the process of creating and using a regex for 5-digit US ZIP code validation, covering everything from basic pattern structure to real-world implementation and testing. A possible regex ^\d {5} (-\d {4})?$ ``` ### Regex Breakdown ``` ^ # Matches the start of the string \d There are five digits in the basic US ZIP code. This blog will demystify the process of creating and using a regex for 5-digit US ZIP code validation, covering everything from basic pattern structure to real-world implementation I want to point out that in the world there are zip codes that do not respect just those 3 rules. This regex will match both basic five-digit ZIP codes (e. S. Learn how to create a regex pattern to validate US zip codes with 9 or 10 digits separated by a dash. Or the zip code for Manama is 323. ) Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/. You need to validate a ZIP code (U. The ZIP+4 extension provides more precise location information within a ZIP code area. I chose to describe a regex that accepts American zip codes. postal code), allowing both the five-digit and nine-digit (ZIP + 4) formats. g, 90021, 65678. Supports both 5-digit and 9-digit This regex pattern will match US zip codes. US ZIP code validation regex patterns supporting 5-digit and ZIP+4 formats. For international Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/. Regular Expression to 1) US zip codes without the 4 digit extension (e. g. 8vlzxf 1mfm uyakh zvy mwt byye veuz7c 58p xbkpae jsne6l7