Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to store telephone numbers in some canonical format or "as entered"?

Storing a telehone number in some kind of canonical format has several advantages from a programmers point of view, but it might confuse the user, if suddenly his entered numbers look a lot different.

What's the way to go?

like image 949
Daniel Rikowski Avatar asked Oct 10 '09 13:10

Daniel Rikowski


People also ask

Should you store phone numbers int or string?

Mobile phone numbers are not stored as integers, as the integer data type holds values that have the potential to be used in calculations. There is no context for using a mobile phone number as part of a calculation, so it is stored as a STRING value.

Why is a telephone number normally stored as a string data type?

Telephone numbers need to be stored as a text/string data type because they often begin with a 0 and if they were stored as an integer then the leading zero would be discounted.


1 Answers

Store it however you prefer, but turn it into human readable format before you show it to the user. And please don't force your users to enter phone numbers in a format of your choosing, let them just type it in however they like.

That's how I do it.

like image 142
Egor Pavlikhin Avatar answered Sep 27 '22 22:09

Egor Pavlikhin