5

I am trying to validate addresses input from users, where they give their street name, zip code, house number etc ...

The question is, how can I validate weather the address is valid?

The even better question would be, how can I check using the IP of the user, weather the input match the current country of the user or not, according to those informations I am gonna flash some validation errors.

Can I implement this in a Google Map for example?

Thanks

Lipo
  • 53
  • 1
  • 4
  • you need to use ip geo location api service,regarding country part, but that does not ensure you 100% because if you use VPN then it is not posible – Maytham Fahmi Apr 12 '17 at 09:20
  • check this as well http://stackoverflow.com/questions/682093/address-validation-using-google-maps-api – Maytham Fahmi Apr 12 '17 at 09:25
  • That was a good hint Maytham, Thanks. To be honest I forgot about the VPN point. You are right. Thanks again – Lipo Apr 12 '17 at 09:29

1 Answers1

7

You can't.

There are simply too many edge cases, where addresses might seem wrongful, but are correct. Where I live some companies get their own zip code, also some roads do and some addresses does not have a town name.

If you want to be as precise as possible, you should ask the user to enter their address through a Google Maps auto complete field, as Google Maps knows a lot of the edge cases.

That being said, It's not accurate to check whether the users inputted address matches their origin country, as they can be behind a VPN. Also some IP addresses maps to another country than the user is actually in.

Hedam
  • 2,209
  • 27
  • 53