Tutorial :What is the international format for telephone numbers



Question:

Is there a format for phone numbers which all numbers will fit into? (something that is more flexible than 3 numbers for the area code and 7 numbers for the rest)


Solution:1

This is tagged as data-modeling.. so I'll address that aspect.

Telephone numbers, regardless of country, should always be stored as a string without formatting (eg. "9083429876").

I see people trying to store these as a string WITH formatting.. and that usually leads to disaster. Somewhere, someone will want those numbers formatted differently. Then you have to write not only a formatting function for them, but an unformatting function as well. Yowsa.

I also see people trying to store these as INT64 (or BIGINT). Well, fine, but why? Noone ever DISPLAYS unformatted telephone numbers.. and to format it you have to turn it into a string. Some try to argue that its for sorting purposes, but that doesn't fly either. Sorting phone numbers is NEVER a useful operation. Filtering numbers based on area code is useful - but returning all the numbers in numerical sorted order? Never useful.

The third bad practive I see is people that store each component of the number in separate fields. Again, not good. The moment you start poking international numbers in there those fields become meaningless.. As an example: do you think Senegal uses Area Codes?

So as a parting thought I leave you with this: Since each country will have its own set of numbers (symbols really) - thought and care should be given to how one till format them for display.


Solution:2

http://en.wikipedia.org/wiki/E.164

http://www.kropla.com/dialcode.htm

Edit: should check what I paste before I actually submit.


Solution:3

The format for all phone numbers is:

  • country code (1-3 digits)
  • the rest

number of digits for a phone number should be 15 or less.

See also wikipedia


Solution:4

Always store the number with a country code so that it is unambiguous and can be formatted correctly for the reader upon display.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »