4
$\begingroup$

After some searching, I haven't been able to find a definite answer.

If I am given a zip code like 11111, it is technically a valid zip code but it doesn't exist. Is there a way to check this? The same goes for a postal code like a1a a1a (valid but not real).

$\endgroup$
5
  • 1
    $\begingroup$ Check out the jQuery Validation library: stackoverflow.com/questions/19011993/… $\endgroup$ Commented Nov 24, 2014 at 21:29
  • 2
    $\begingroup$ You should probably include which country you're talking about or if this is regarding any countries specifics $\endgroup$ Commented Nov 24, 2014 at 21:29
  • 2
    $\begingroup$ The USPS has an API (usable for a fee) for validating actual ZIP codes. As ZIP codes can be added as needed, they would be the only reliable source for validity. $\endgroup$ Commented Nov 24, 2014 at 21:31
  • 1
    $\begingroup$ "The same goes for a postal code like a1a a1a (valid but not real)." What country is this valid in? It looks almost like a UK postcode, but the second part always starts with a digit, so it wouldn't be valid here. "A1A 1AA" is technically a valid form, I think. $\endgroup$ Commented Nov 24, 2014 at 21:49
  • $\begingroup$ That was a Canadian one. Looks like the only solution is to compare it against a dataset. I was just foolish in thinking there would be a way to check using a few rules XD. $\endgroup$ Commented Nov 24, 2014 at 22:23

2 Answers 2

6
$\begingroup$

For United States zipcodes:

You can purchase / download databases of zip codes, which you can use in your local app.

Google for

us zip code database

Here is one that you can use for free for non-commercial purposes (for commercial purposes you can purchase a cheap license):

http://www.unitedstateszipcodes.org/zip-code-database/

There are some providers which allow you to perform remote HTTP calls, search around

$\endgroup$
Sign up to request clarification or add additional context in comments.

Comments

1
$\begingroup$

For any who stumble onto this and are using Python, this exists: https://github.com/Brobin/usps-api

It doesn't cover all the API functionality, but it makes the standard stuff much easier than constructing XML by hand.

$\endgroup$

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.