Validating US zip codes
Validating zip codes at the client side can be useful on web pages with address forms.
Entering numbers is an error-prone process. It would be great for the user if we could provide some kind of basic immediate validation to inform them of a possible error in their data entry.
On the other hand, a satisfyingly complete zip code database has a non-trivial size. Loading the complete database at the client side might be difficult and non-optimal.
In this recipe, we're going to write a client-side zip code validation function. In the process, we're going to learn what it takes to convert a non-trivial zip code database to a smaller representation which can be loaded at the client side.
Getting ready
Let's download the zip code database file first. The unitedstateszipcode.org website provides a free zip code database in a CSV format (http://www.unitedstateszipcodes.org/zip-code-database/).
We're going to extract a smaller database from this file which can be loaded at the client...