Storing phone numbers in a database.

Glenn

Member
I am creating a user id for a web site and in the site, the user enters a phone number, only numbers, 10 digits. When they enter fewer digits, it stores the number fine but when they enter 10 digits, it saves the number 2147483647 no matter what they put in. What is happening here.
 

MarkR

New Member
Funny, I just noticed a bug in a system I'm working with today which does this.

Int in mysql defaults to a 32 bit storage capacity, 2147483647 is 2^32 -1. If your number is bigger than that, to prevent overflow it'll just store it as the the highest 32 bit number possible aka 2147483647.

Really when storing phone numbers you should store it as a varchar, this is because if your phone number is 0123456789, int will truncate the leading zero and store 123456789. So my suggestion is change your storage type to varchar.
 
Top