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

前端 未结 18 1447
佛祖请我去吃肉
佛祖请我去吃肉 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:44

    Perhaps storing the phone number sections in different columns, allowing for blank or null entries?

    0 讨论(0)
  • 2020-11-28 19:44

    The standard for formatting numbers is e.164, You should always store numbers in this format. You should never allow the extension number in the same field with the phone number, those should be stored separately. As for numeric vs alphanumeric, It depends on what you're going to be doing with that data.

    0 讨论(0)
  • 2020-11-28 19:46

    Look up E.164. Basically, you store the phone number as a code starting with the country prefix and an optional pbx suffix. Display is then a localization issue. Validation can also be done, but it's also a localization issue (based on the country prefix).

    For example, +12125551212+202 would be formatted in the en_US locale as (212) 555-1212 x202. It would have a different format in en_GB or de_DE.

    There is quite a bit of info out there about ITU-T E.164, but it's pretty cryptic.

    0 讨论(0)
  • 2020-11-28 19:46

    I find most web forms correctly allow for the country code, area code, then the remaining 7 digits but almost always forget to allow entry of an extension. This almost always ends up making me utter angry words, since at work we don't have a receptionist, and my ext.# is needed to reach me.

    I would have to check, but I think our DB schema is similar. We hold a country code (it might default to the US, not sure), area code, 7 digits, and extension.

    0 讨论(0)
  • 2020-11-28 19:48

    KISS - I'm getting tired of many of the US web sites. They have some cleverly written code to validate postal codes and phone numbers. When I type my perfectly valid Norwegian contact info I find that quite often it gets rejected.

    Leave it a string, unless you have some specific need for something more advanced.

    0 讨论(0)
  • 2020-11-28 19:49

    I would go for a freetext field and a field that contains a purely numeric version of the phone number. I would leave the representation of the phone number to the user and use the normalized field specifically for phone number comparisons in TAPI-based applications or when trying to find double entries in a phone directory. Of course it does not hurt providing the user with an entry scheme that adds intelligence like separate fields for country code (if necessary), area code, base number and extension.

    0 讨论(0)
提交回复
热议问题