I just tested the sample file and was impressed with the speed of this system, however there is a problem with relying on zip for town names. There are quite a few towns, rural districts, and unincorporated-but-named areas which share a single zipcode across mutliple place names. I am familiar with this as the problem arises with a family-member's address I use frequently, and the name which that zipcode fills in is not correct when using this particular technique, even with the currect street address filled in before the zipcode.
If zipcodes were unique to a single town/area name, it would probably always work, but I encounter this specific type of error regularly, and haven't found a system which works consistently yet.
One would need a database to provide a value list of all the possible place names for each zip code so one could pick the correct name when there are multiples.
Actually this API returns all cities/townships for a given zip code and my script just grabs the first one. This just gets it right most of the time, but it is not perfect. But since it does return multiple places, you could have it prompt the user when there are multiple locations to pick the correct one. That would be an improvement on this script.
It sounds like Jeremy has a bit of experience here. Jeremy, do you have a favorite API for address assistance/confirmation?
This is why USPS has the 9 digit zip code. #####-####
However, most people don't use it and its may not be available for entry/lookup.
I would think that entry of address and city would be favorable to give you the full zip code.
But all things are not perfect. My zipcode spans 3 counties, for example...
I suspect that using a geolocation API for filling in address data may address this issue — a street address and a postal code together hypothetically gives the service enough information to uniquely identify the correct city — but I haven't checked or tested this. Another thing to bear in mind is that different services may specify a "city", "town", and "village" for each address in certain locations, and these will all be different for one location. It's up to you to figure out which is appropriate for your application.