aspose file tools*
The moose likes Java in General and the fly likes What is a good format for international mailing addresses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is a good format for international mailing addresses" Watch "What is a good format for international mailing addresses" New topic
Author

What is a good format for international mailing addresses

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

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

Joined: Oct 27, 2005
Posts: 19719
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is a good format for international mailing addresses