Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Address field validation for iOS / Mac

I want to create an "Add Address" view, a very basic "Street, City, Zip, Country" type of page: multiple text fields inside a table view. This is simple if you only ever added U.S addresses, but I'm not sure about how to do this the right way though, handling all international use-cases as well. Essentially: 1. How do you pick the right field label for each country? For e.g. for US / Australian addresses, the field should be called "State"; for UK, it's called "County", in some places it's called "Province". How do you know what the label should say (short of hard-coding logic myself for each country)? 2. How do you validate the values for those field? UK postal codes have a certain format, whereas in the US it's a 5-digit ZIP code. Also, in the US, there is a list of states that the user can select. How do you get that list?

I've looked into NSLocale, and can't find any way to do this. Surely there must be a good and easy way to do this?

like image 596
Z S Avatar asked Feb 19 '14 00:02

Z S


2 Answers

I dug around and in the end the best thing I found was a guide on "The good international address field form", but it'll still be hard to validate it. I don't think it's done.

http://www.uxmatters.com/mt/archives/2008/06/international-address-fields-in-web-forms.php

One method could be to reverse lookup the address through mapkit.

like image 61
Theis Egeberg Avatar answered Nov 16 '22 20:11

Theis Egeberg


You can try to simplify the UI by adding just one text field and ask user to enter his address in an arbitrary way, and then use CLGeocoder class to convert the string to instance of CLPlacemark, which is a convenient container for such information as country, postal code, etc.

like image 31
nalexn Avatar answered Nov 16 '22 20:11

nalexn