There are several companies that publish catalogs of US zip codes, usually not very expensive, and some even come with lat / lon data. This is the most common way to check a city or state in the United States or North America. Zip codes around the world in a country and city are likely to be a more difficult problem, or at least more expensive.
Another approach would be to use the Google Maps API, perhaps in combination with the data that you can get from location-oriented browsers (all modern). Honestly, some time has passed since I used the API, but it seems like I remembered that you can get some pretty detailed information considering lat / lon. Google now charges you for high usage of the Maps API, but if your site has even moderate traffic, you are probably still in the free zone.
At some level you will have to trust users. I remember some time ago we discovered anomalies in custom zipcodes in our database - it seemed that everyone lived in Beverly Hills, California. It was around 2000, when the original version of the "90210" TV show was still around - that zipcode :-).
source share