Is there a standard for storing normalized phone numbers in a database?

前端 未结 18 1509
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 19:23

What is a good data structure for storing phone numbers in database fields? I\'m looking for something that is flexible enough to handle international numbers, and also som

18条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 19:29

    I've used 3 different ways to store phone numbers depending on the usage requirements.

    1. If the number is being stored just for human retrieval and won't be used for searching its stored in a string type field exactly as the user entered it.
    2. If the field is going to be searched on then any extra characters, such as +, spaces and brackets etc are removed and the remaining number stored in a string type field.
    3. Finally, if the phone number is going to be used by a computer/phone application, then in this case it would need to be entered and stored as a valid phone number usable by the system, this option of course, being the hardest to code for.

提交回复
热议问题