Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The state of the address, preferably following the city and a comma. Always two

`zip`

The 5 digit zip code of the address, preferably following the state. 9 digit zips not yet supported. E.g. 123 W. Mifflin St., Madison, WI __53703__
The 5 or 9 digit zip code of the address, preferably following the state. Supported 9 digit zips format is (xxxxx-xxxx). E.g. 123 W. Mifflin St., Madison, WI __53703__

`full_address()`

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ Always two capitalized letters. E.g. 123 W. Mifflin St., Madison, **WI**

``zip``

The 5 digit zip code of the address, preferably following the state. 9
digit zips not yet supported. E.g. 123 W. Mifflin St., Madison, WI
The 5 or 9 digit zip code of the address, preferably following the state. 9
digit zips supported in the format (xxxxx-xxx). E.g. 123 W. Mifflin St., Madison, WI
**53703**

``full_address()``
Expand Down
4 changes: 3 additions & 1 deletion address/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def preprocess_address(self, address):

def check_zip(self, token):
"""
Returns true if token is matches a zip code (5 numbers). Zip code must be the last token in an address (minus anything
Returns true if token is matches a zip code (5 numbers or 9 numbers). Zip code must be the last token in an address (minus anything
removed during preprocessing such as --2 units.
"""
if self.zip is None:
Expand All @@ -290,6 +290,8 @@ def check_zip(self, token):
# print "zip check", len(token) == 5, re.match(r"\d{5}", token)
if len(token) == 5 and re.match(r"\d{5}", token):
self.zip = self._clean(token)
if re.match(r"\d{5}-?\d{4}", token):
self.zip = self._clean(token)

return True
return False
Expand Down
Loading