Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you store cell phone numbers in a database?

Tags:

With the age of text messages and things like that, what's a good way to store phone numbers in a database?

In the USA, text messages are handled by phone numbers but in other countries I hear they use email addresses so I guess there needs to be a way to differentiate between countries that use cell phone numbers as their address.

Addition: For example, people in the USA might use 432-342-3333 or 1-432-342-3333 while in the UK they might use +44 800 400000 or they might even leave out the 44. The 44 and the 1 makes a difference when automatically sending out SMS. However, checking the phone number for each country can get tedious. In this case, would you split the country code or would you merge it into a single column and deal it with it there?

like image 800
danmine Avatar asked Nov 24 '08 16:11

danmine


2 Answers

I would primarily use a text field, or a series of text fields, even if you are using a numerical phone number for the following reasons.

  1. Phone numbers have a great range of values, including extension numbers which may result in numerical columns losing precision.
  2. Losing precision in a phone number is rather bad.
  3. There is no logical reason to want to perform math ( addition/multiplication ) on a phone number.

Additionally, you may want to specify how you are using this data. If you are planning an automated messaging service, you're going to need a series of relaying agents to broadcast via, so you may as well add an identifier that pertains to the relay the information pertains to. Then all you have to worry about is that the relaying agent can understand the content in the text fields.

like image 178
Kent Fredric Avatar answered Sep 20 '22 05:09

Kent Fredric


Generally as text, you don't need all the fancy formatting, unless you need it to parse numbers from different countries that you can't distinguish otherwise. You can always add the formatting later on.

Not as a number!!! Leading zeros may be problematic.

like image 42
vfilby Avatar answered Sep 22 '22 05:09

vfilby