Why is it best to store a telephone number as a string vs. integer?

前端 未结 5 640
死守一世寂寞
死守一世寂寞 2021-02-01 12:50

As the question states, why is it considered best practice to store telephone numbers as strings rather than integers in the telephone_number column?

Not sure I understa

5条回答
  •  没有蜡笔的小新
    2021-02-01 13:23

    There is several reasons for this :

    • Phone numbers often start with a "0" : an integer will remove all leading "0"s
    • Phone number can have special char : +, (, -, etc. (for exemple : +33 (0)6 12 23 34)
    • You cannot perform operations on phones : adding phones, for instance, would be meaningless
    • Phone number may be internationalised, i.e. different format for different people, thus not possible with integers

    There might be other reasons, but I guess that's already a fair amount of those :)

提交回复
热议问题