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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access