views:

208

answers:

5

I need to store phone numbers starting with 0 but whenever i try to store this in MySql table the starting ZERO is removed because no number start with Zero actually

how i can solve this problem please do i need to change the field type from Integer to another type

please help

A: 

You can use data type as varchar to solve this.

Karthik
A: 

Phone numbers aren't integers and you will only end up with problems trying to store them as integers, store them as strings instead.

myforwik
A: 

Phone numbers are not really numbers in the sense that they aren't ordinal. They're just characters - they fact that they are numbers is incidental.

Store them in a varchar and move on :D

Peter Bailey
+2  A: 

Phone numbers can contain other symbols for readability too... a regexp for a phone number looks something like [0-9+-()*#]+. So you need to use a text field for phone numbers, plus some validation.

Andrew McGregor
a few other formats to consider: 555/555-1212, 555.555.1212, 555-555-1212 x123
nathan
Hence 'something like'... validating phone numbers is tricky. I guess `[0-9 +-()*#x.,/]+` gets close.
Andrew McGregor
+1  A: 

Yes - numeric fields only store the numeric values, not the formatting of those (which paddin with leading zeroes is). You should either

  1. change the field type from integer to varchar or char (if # of digits is ALWAYS the same).

  2. Store the number as integer BUT prepend 0 in your presentation layer as needed.

DVK