ruby-on-railsrubyruby-on-rails-3postgresqlruby-on-rails-4

Why is it best to store a telephone number as a string vs. integer?


As the question states, why is it considered best practice to store telephone numbers as strings rather than integers in the telephone_number column?

Not sure I understand the rationale for this. Please help clear this up!

Thanks!


Solution

  • Telephone numbers are strings of digit characters, they are not integers.

    Consider for example:

    Storing the string version of the telephone number makes this clear and unambiguous.


    History: On old pulse-encoded dial systems, the code for each digit in a telephone number was sent as the same number of pulses as the digit (or 10 pulses for "0"). That may be why we still use digits to represent the parts of a phone number. See http://en.wikipedia.org/wiki/Pulse_dialing