• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is a good format for international mailing addresses

 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic