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

前端 未结 5 552
死守一世寂寞
死守一世寂寞 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:12

    What Neil Slater said is correct. I would add that there are lots of edge cases where you can't express a telephone number as a number value consistently.

    For example, consider these numbers:

    011-123-555-1212
    +11-123-555-1212
    +1 (112) 355-5121 x2
    

    These are all potentially valid phone numbers, but they mean very different things. Yet, in integer form, they are all 111235551212.

提交回复
热议问题