Storing a Tele #

What is the best way to store a Telephone # in MySQL?

Presumably my form would be asking people for a number formatted like…

(AAA) EEE-NNNN

but then again maybe I want to leave things more free-form?!

TomTees

  1. Generally I agree with r937, but once I got to code an area code update program to update existing customer files with new area codes. In the case I did the three digits of the exchange determined if the number got a new area code or not, and it would have been easier to code the program if the exchange part was in a separate field. In my case the customer’s application didn’t enforce any format on the stored phone number, a couple thousand stand-alone systems with typically a few thousand customers in each of their customer’s systems. This made parsing the phone # string quite an adventure.

In my applications I have always enforced a format on the stored phone #, both for the visual niceness and to make later parsing of the number easier.

Okay, however…

1.) Should I use an overly big field like VARCHAR(25) in case the add extra characters, e.g. (999) 555-1212 and to handle things like extensions?

2.) Is it okay to store non-numeric characters as described above?

3.) What is the best way to handle capturing the data in a web form?

4.) Is there a need to get fancy with Regular Expressions?

5.) Is there any benefit breaking up a Tele # into three or more fields, e.g. AreaCode, Exchange, Number, Extension?

TomTees

I second this, I’ve always stored phone numbers as strings not numbers.

It is not uncommone to see 3 fields in a web-form: Area Code, Exchange, Number

I’m not sure it is any more work, and could be less work for reasons you mentioned.

TomTees

1 yes
2 yes
3 a text box
4 no
5 no

Best thing to do is store them as text!