views:

458

answers:

3

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)

+5  A: 

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

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

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

Hooray Im Helping
A: 

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

Fortega
+6  A: 

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.

Boo