NYCPHP Meetup

NYPHP.org

[nycphp-talk] storing phone numbers in MySQL

Mitch Pirtle mitchy at spacemonkeylabs.com
Wed Mar 10 17:14:49 EST 2004


David Mintz wrote:

>This isn't the sexiest and most thrilling of topics, but I'm just curious.
>
>When you guys store 10 digit phone numbers in a MySQL database, generally
>speaking, how do you do it -- data type, width, format? Do you strip all
>the non-digits so as to make them format-agnostic, and reformat them at
>fetch time? Or do you enforce a format like (xxx) xxx-xxxx so they'll all
>be consistent? Do you keep a separate column for an optional extension, or
>allow enough width for "(xxx) xxx-xxxx Ext.xxxx" ?
>
>Hey you in the back of the room, stop snoring.
>  
>
(snaps head up)  Hey who what the...  Oh.

I used to break them up as separate fields, but that can get messy as 
soon as you go international.  Since then I store:

    area_code
    prefix
    suffix
    extension

..and get the country code from their address.  If no address, then you 
need to get that too.  In the 30 or so countries I've targeted with 
weblications, I've never seen an alpha character in use, unless you 
count stuff like 1-800-big-blob or something like that.  By using PEAR's 
HTML_QuickForm, it is pretty easy to ensure you are only getting numeric 
data - and providing helpful messages too.

(puts head back down)




More information about the talk mailing list