How to collect and store postal addresses

Ismayil Khayredinov
The Startup
Published in
2 min readJan 17, 2020

--

Photo by Rae Tian on Unsplash

It’s 2020, and one thing the internet can’t agree on is how to collect and store postal addresses. Every website you look at has its own format and naming convention. Your browser’s autofill chokes every time someone invents a new label for the infamous zipcode. Not to mention the time you spend mapping address schemas between your front end, back end, payment processor, shipping partner, accounting software, and you name it.

I am going to share the schema I have been using for the past 5 years across a number of international applications and websites. It served me well and didn’t require any mental acrobatics to get used to. Zipcodes, just like feet, pounds and miles, have no place in a globalized world, at least not when it comes to storing data in a standardized manner, that will withstand localization needs of an international postal economy.

Don’t use titles

Title is an ambiguous word and leads to all kinds of confusion in your code. Use salutation instead to make things clearer.

Not everyone lives in a city

Use locality instead of a city, as it encompasses cities, villages and other types of settlements that exist around the world.

Not everyone lives in a federalized country

States are administrative units in the United States. Other countries have provinces, territories, regions, republics et al. Region is a more appropriate convention that allows people to include additional information about the region of the country they live it, be it an American state or a rayon in a Russian federal republic or an oblast in Ukraine.

F*** zipcodes

Zipcodes are a thing in North America — leave them be. The rest of the world uses postal codes.

Country/State select?

Unless you are serving a US/Canadian market exclusively, just forget it. People can type in a 2-letter state code, or type out the name of their state. Does it make any difference to you? It doesn’t for the postal service.

Store country codes

Store an ISO2 or an ISO3 code of the country, instead of or alongside the country name. You will end up needing country information in user’s language as well as your own — save yourself some trouble by storing the ISO codes instead and localizing based on the use case.

Address Validation

Just don’t. Nobody gives a damn. You end up with hundreds of lines of regex, which don’t begin to cover the diversity of world geographies. Just trust your users to provide a valid address.

Address Output

Addresses are as diverse as are people in the world, and none of them like triple trailing commas (, , Berlin,). Don’t expect every address to have all parts of the schema.

I hope you enjoyed my rant. Cheers.

--

--

Ismayil Khayredinov
The Startup

Full-stack developer, passionate about front-end frameworks, design systems and UX.