How to check the location address on the form?

I want to confirm that the mailing address filled in by the user is correct.

Assuming we have the fields street, street_number, postal_code, city and country

How can I show errors when a user, such as that his country is France and is a city of New York?

or

How can I find that the zip code does not match the city?

Is there a strategy to solve this problem with Ruby On Rails or am I just trusting user records?

+4
source share
2 answers

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

+3
source

Have you only considered the jQuery address validation plugin for you? It is free for many users, up to 250 search queries / month and always up to date (you do not need to maintain a database).

By the way, I work for SmartyStreets. There's also a zip code API to search if cities match zip codes and vice versa. In any case, we made a lot of efforts to make the user’s work positive, even if the address they type is not completely valid.

+3
source

Source: https://habr.com/ru/post/1446109/


All Articles