Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the international format for telephone numbers

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)

like image 489
Ralph Shillington Avatar asked Dec 04 '22 15:12

Ralph Shillington


1 Answers

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.

like image 68
Sam Axe Avatar answered Dec 06 '22 04:12

Sam Axe