Question

I have a Flex application that needs to be able to validate hundreds of zip codes fairly quickly. I also want to keep the memory space used by the app as small as possible.

Here are a few solutions my team has come up with. Any thoughts on them? Any other ideas?

Check each zip code via...

  1. array of valid zip codes
  2. array of invalid zip codes
  3. soap call to a web service that validates zip codes
  4. query a database table
  5. a tree - 5 nodes high, nodes at the bottom would have boolean values of whether or not the zip is valid. The zip code of 12345 would go from the root to it's first child, to it's second... you get the point
  6. validate first 3 numbers via array of valid USPS SCFs then the last two digits via array specific to that SCF.
Was it helpful?

Solution

Depends on what you are looking for. Do you want to validate the format of the zip code (ie. that it is 5 digits long) or do you want to ensure the zip code is a valid US zip code. I will venture a guess that it is the latter. Take a look at the USPS address API (https://www.usps.com/business/webtools-address-information.htm?). I am willing to bet that will be perfect and less overhead then managing a DB or updating an array and managing all the xxxxx+4 zip codes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top