O'Reilly logo

HTML5 Data and Services Cookbook by Mite Mitreski, Gorgi Kosev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required