Search code examples
iphonevalidationpostal-code

What is the quickest way to validate a postal code as existing on the iPhone?


I have an iPhone application which accepts valid zip codes as input. The input can be quickly validated for format; I am looking for methods to validate whether it exists or not.

What is the most efficient way to test whether a given Canadian or US postal code exists, without storing a database of valid codes on the phone?


Solution

  • You can use a regex, but that will only tell you if the code is in the valid format, but doesn't tell you if the zip code actually exists. For example, "99999" is a valid US zip code format (5 digits), but is not a valid zip code.

    I'd find some online service that allows you submit a zip code and returns you the cities that correspond to it. Some online weather services (Yahoo, Weather.com) have a developer API that is pretty easy to integrate.