Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store phone numbers on MySQL databases? [duplicate]

Possible Duplicate:
mysql datatype for telephne number and address

Any suggestions on best practice to store telephone numbers in a DB? Consider a US phone number:

  • 555 555 1212
  • 555-555-1212
  • (555) 555 1212
  • 5555551212
  • 1-555-555-1212
  • 1 (555) 555-1212
  • and so on ...

Should I remove formatting and store only numbers? Should I just use one field -- or split them up into: country code, area code, phone number, etc.? Suggestions?

like image 431
StackOverflowNewbie Avatar asked Nov 27 '11 09:11

StackOverflowNewbie


People also ask

What is the best way to store phone numbers in database?

A phone number should always be stored as a string or text and never an integer. Some phone numbers generally use hyphens and possibly parentheses. Also, you might need to indicate the country code before the phone number such as +46 5555-555555.

Which data type is best for storing a phone number?

I generally use VARCHARs to store telephone numbers. Storage is not so expensive these days that I benefit that much from the savings found by storing them as numeric values.

How do I save a phone number in SQL?

Use CHAR to Store Phone Numbers in MySQL The CHAR datatype (short for character) can store strings of fixed length between 0 and 255 characters. A column implementing CHAR can specify an upper limit constraint between 0 and 255, and MySQL expects every string in that column to be of the same size.


1 Answers

  • All as varchar (they aren't numbers but "collections of digits")
  • Country + area + number separately
  • Not all countries have area code (eg Malta where I am)
  • Some countries drop the leading zero from the area code when dialling internal (eg UK)
  • Format in the client code
like image 74
gbn Avatar answered Sep 22 '22 14:09

gbn