When you automate a service that uses telephone numbers, they cause more complications than you might expect. This starts when you want to know how to format a telephone number.
Store telephone numbers as text
To start with, trying to use a number field for a telephone number doesn’t work.
Telephone numbers include non-digits, such as
+, significant leading zeroes, and separators such as spaces and dashes.
Fortunately, you don’t need arithmetic: adding two telephone numbers together doesn’t give you anything useful.
Telephone numbers share this confusion with other non-numeric ‘numbers’.
You can’t store a telephone number as a number, and format it when you display it. Instead, to start with, collect and store telephone numbers as text, using the formatting they came with.
Expect numerous formats
Most people group telephone number digits in twos or threes, while some conventions use groups of four or five digits. You see a lot of variation between telephone numbers in different countries.
|Typical landline format
|Typical mobile format
|0x xx xx xx xx
|06 xx xx xx xx
|xx xx xx xx xx
|xx xx xx xx xx
|0xx-xxx xx xx
|0xxx xxx xxxx
Even within one country, you find various grouping conventions. Countries that only use ten-digit numbers, for example, typically have more than one way to write them. Except Quebec.
According to Wikipedia, ‘Educational institutions of Quebec will mark improperly written phone numbers as orthographical mistakes in academic texts.’ The rest of us live in chaos, I suppose.
International standards don’t help much
International standards reduce telephone number format variation a little. ITU-T recommendation E.123 Notation for national and international telephone numbers, e-mail addresses and Web addresses (2001), explains digit-grouping, for example:
2.9 Grouping the digits of a telephone number is advisable for reasons of memorizing, oral presentation, and printing.
9.1 Grouping of digits in a telephone number should be accomplished by means or (sic) spaces unless an agreed upon explicit symbol (e.g. hyphen) is necessary for procedural purposes. Only spaces should be used in an international number.
These standards only go so far: each country still has its own numbering plan. Some countries use a fixed-length ‘closed’ numbering plan, while telephone numbers in countries with open numbering plans vary in length. As a result, you won’t find an international way to format a telephone number with digits in groups.
While telephone numbers in many countries all have ten digits, for example, telephone numbers in Italy vary, with 6-11 digit landline numbers.
Telephone number formatting approaches
Given this international variation, you get to choose between the following approaches.
- Use whatever user input format you get, so people can choose, at the cost of less overall consistency.
- Only format telephone numbers for one country, and use the wrong format for every other country.
- Only use international numbers with no grouping, like + xxxxxxxxxxx, for overall consistency.
- Use a database of every country’s numbering plans and area codes to use the right format for each city, world-wide.
Needless to say, each approach has its pros and cons.