29

Before you say that this has already been asked, know that I've already reviewed these:


Say I'm working on a program that has to deal with phone numbers, and I want to make sure that they're saved and displayed in a standard format, so other programs and humans can also understand them predictably & consistently.

For instance, I've seen the following all be valid representations for the same US phone number:

  • 1234567
  • 123-4567
  • 123 4567
  • 5551234567
  • (555) 1234567
  • 555-1234567
  • 555 123 4567
  • 555-123-4567
  • (555)-123-4567
  • (555) 123-4567
  • (5) 123 4567
  • 1-555-123-4567
  • (1) 555-123-4567
  • +1 555-123-4567
  • +1 555 123-4567
  • +1 (555) 123-4567
  • Ad nauseum…

And then different countries represent numbers in different ways:

  • 55 1234 567 8901
  • 55 12 3456 7890
  • 55 123 456 7890
  • 55 1234 567890
  • 555 123 456
  • (55) 123 4567
  • 5.555.123-45-67
  • Ad nauseum…

As you can see, the number of ways a user can see a valid phone number is nearly infinite (The Wikipedia page for Telephone numbers in the UK is 26 printer pages long). I want all the numbers in my database and on the screen to be in a universally-recognizable format. As far as I can tell, ISO and ANSI have no defined format. Is there any standard notation for phone numbers?

5
  • 1
    Have you checked this question?
    – Emmanuel N
    Commented Apr 1, 2013 at 14:44
  • @EmmanuelN That question was from 2008. I was hoping some standards organization had come up with one in the past 5 years.
    – Ky -
    Commented Apr 1, 2013 at 14:46
  • I think this one might help you more.
    – Emmanuel N
    Commented Apr 1, 2013 at 14:49
  • Sorry, those aren't quite relevant. See my edit, which added a "Reviewed Questions" section.
    – Ky -
    Commented Apr 1, 2013 at 14:58
  • 1
    @Supuhstar: check out this link it might help u link Commented Jan 15, 2014 at 14:55

2 Answers 2

67
+50

There's no ISO standard, but there are ITU standards. You want E.123 and E.164.

In summary, any phone number is represented by +CC MMMMMM... where CC is the country code, and is one to three digits, and MMMMMM... is the area code (where applicable) and subscriber number. The total number of digits may not be more than 15. The + means "your local international dialling prefix".

I'll give a few examples using my own land line number.

So, for example, if you are in Germany, the number +44 2087712924 would be dialled as 00442087712924, and in the US you would dial it as 011442087712924. The 44 means that it is a UK number, and 2087712924 is the local part.

In practice, the long string of MMMMM... is normally broken up into smaller parts to make it easier to read. How you do that is country-specific. The example I give would normally be written +44 20 8771 2924.

As well as the unambiguous E.123 representation above, which you can use from anywhere in the world that allows international dialling, each country also has its own local method of representing numbers, and some have several. The example number will sometimes be written as 020 8771 2924 or (020) 8771 2924. The leading 0 is, strictly speaking, not part of the area code (that's 20) but a signal to the exchange meaning "here comes a number that could go outside the local area". Very occasionally the area code will be ommitted and the number will be written 8771 2924. All these local representations are ambiguous, as they could represent valid numbers in more than one country, or even valid numbers in more than one part of the same country. This means that you should always store a number with its country code, and ideally store it in E.123 notation. In particular you should note that phone numbers ARE NOT NUMBERS. A number like 05 is the same as 5. A phone number 05 is not the same as 5, and storage systems will strip leading zeroes from numbers. Store phone numbers as CHAR or VARCHAR in your database.

Finally, some oddities. The example number will be written by some stupid people as 0208 771 2924. This is diallable, but if you strip off the leading 0208 assuming that it is an area code, then the remainder is not valid as a local number. And some countries with broken phone systems [glares at North America] have utterly bonkers systems where in some places you must dial all 10 digits for a local call, some where you must not, some where you must dial 1NNN NNN NNNN, some where you must not include the leading one, and so on. In all such cases, storing the number as +CC MMMMM... is correct. It is up to someone actually making a call (or their dialling software) to figure out how to translate that into a dialable sequence of digits for their particular location.

2
-2

There is a lot of local countries standards. On one of my projects I had the same problem. Solved as:

  1. In DB everything stored as numbers: 123456789
  2. Depending on selected web page language, this number pre-formatted when page loads.

Examples:

  • France, Luxemburg format phone numbers like 12.34.56.78.90 or 12 34 56 78 90
  • Germany: 123 45 67 or 123-45-67
  • Great Britain: 020 1234 1234 or 1234 01234 12345
  • Italy, Netherlands: 12 1234567 or 020-1234567
  • CIS countries: 123 123-45-67
3
  • 5
    "everything is stored as numbers" I hope you mean stored as a string value holding numerics?
    – Crono
    Commented May 11, 2016 at 22:51
  • Germany: The - is used to infix the area code and to indicate when/if a subscriber's extension starts. For example +49-NN-12345-123 (NN = e.g. 2 digit area code) tells you the extension is -123 and that -0 (+49-NN-12345-0) usually is a central number of a receptionist in a hospital, institution, university etc. Sometimes the called people pass you on to a colleague by giving the extension, then it is also useful to know where to append it as not all extensions need to have the same length (as long a no extension appears as prefix in another).
    – hokr
    Commented Mar 1, 2017 at 10:58
  • In Germany, there is the DIN 5008 standard for writing and layout rules, which also makes recommendations for phone number formats. Generally, the dash is used at most once to separate extension numbers.
    – mike
    Commented Oct 30, 2023 at 11:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.