Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a good format for international mailing addresses

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, this is not really a Java problem, but a design one.

In the US, an address has one or two street lines, a City, State, and Zip.
To make your Address class work in both the US and Canada, you need to add a "country" field and allow the zip code to be 7 characters, with alphabet characters.

What is the reasonable generalization for full International mailing/postal addresses?

What are the limits for field lengths? For example, in the US, a city within a state can be completely specified in 13 or fewer characters. So there is no need to have the City field in a database be longer than char(13)

Are there similar rules for international Cities, Countries, etc.?

Do all international postal addreses have something similar to the Zip or Postal code?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a tough question indeed. The differences between countries are very diverse unfortunately.

Pat Farrell wrote:What are the limits for field lengths? For example, in the US, a city within a state can be completely specified in 13 or fewer characters. So there is no need to have the City field in a database be longer than char(13)

Outside the US there are no such limitations. My own city has 16 characters, and there are certainly cities with longer names. At my company we usually use 50 or 100 as field size. For address fields it's usually 255, sometimes longer. Zip codes are 10 or 20. Countries are stored in a different table with a relation between the two.

Are there similar rules for international Cities, Countries, etc.?

For countries check out ISO 3166. It defines the available countries and for each country a unique 2-digit, 3-digit and numeric code. That's why we store countries in a different table. The set is limited so we have already added (almost) every country to it, so we know that users can't mistype a name. For exports we can choose which of the fields to display: 2-digit, full name, native name, etc.

Do all international postal addreses have something similar to the Zip or Postal code?

You can't make zip codes required for all countries. Some countries have them, some don't, some partly. In the UK there are even streets where each house has its own zip code, or streets with only one house.


Summarizing how we do it:
- address1: varchar(255), multi line. Sometimes the house number is explicitly split off to its own field.
- zip code: varchar(10) or varchar(20), can't remember
- city: varchar(50) or varchar(100)
- country: int to its own table
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic