469,621 Members | 2,244 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Format Phone Number

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
Nov 16 '05 #1
6 28414
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" wrote:
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

Nov 16 '05 #2
Poewood wrote:
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.
Nov 16 '05 #3
Tom Porterfield wrote:

Poewood wrote:
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);


or:

iPhone.ToString("(###) ###-####");
Nov 16 '05 #4
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

"Poewood" <Po*****@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
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

Nov 16 '05 #5
Drebin wrote:
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

"Poewood" <Po*****@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
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


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
:)
Nov 16 '05 #6
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by joemono | last post: by
5 posts views Thread by Kamaluokeakua | last post: by
3 posts views Thread by Mike | last post: by
4 posts views Thread by Brian Henry | last post: by
1 post views Thread by womblesjc | last post: by
10 posts views Thread by JackM | last post: by
2 posts views Thread by jeswin12 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.