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
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
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!