Format Phone Number

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to parse the contents of a textbox into a phone number format?
Actually I would like to save the input as a number but display it as a
phone number in the typical US format (000) 000-0000.

Thanx in advance,
Poe
 
I can only suggest that you iterate through the string entered and check each
character to see if it's either a ' ( ' , a ' - ' or a ' ) ', or a digit.
If each is in the correct position in the array, fine, otherwise send a
MessageBox to the screen advising to enter correct format.

I would also suggest that you wait for another reply as I have only been
studying programming for a few months.
 
Poewood said:
Is there a way to parse the contents of a textbox into a phone number format?
Actually I would like to save the input as a number but display it as a
phone number in the typical US format (000) 000-0000.

Thanx in advance,
Poe

int iPhone = 7065551212;
string strPhone = string.Format("{0:(###) ###-####}", iPhone);
--
Tom Porterfield
MS-MVP Windows
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
If there is any remote possibility this will be used internationally, be
advised that there is not much logic to phone number lengths and formats
outside the US. The length of a phone number can be different between towns
even in the same country
 
Drebin said:
If there is any remote possibility this will be used internationally, be
advised that there is not much logic to phone number lengths and formats
outside the US. The length of a phone number can be different between towns
even in the same country

Most places have a standard phone number format.
Aus (00) 0000 0000
If someone really wanted to be clever, they could allow the user to set
the desired phone format using a system config class or such.

JB
:)
 
Hi Guys,

For some European countries, e.g. Sweden, this would not be applicable.
In Sweden the area code can be 1-3 digits long excluding the starting 0
if you call from within Sweden. Then the actual phone number can be 5-8
digits long, depending on which area code you have dialed.

BR
/Joakim
 
Back
Top