473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the best way to format a phone number

I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Any suggestions is appreciated.
Nov 21 '05 #1
6 17889
Do you need it for London. Paris, Lyon or for Amsterdam?

To show you that this can be even different for cities.
AS far as I know is this not in the globalization. so you have to write it
yourself however there are lot of samples how to do it by instance for the
US on Internet..

I hope this helps,

Cor
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Nov 21 '05 #2
* "KFactor" <kf******@hotma il.com> scripsit:
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?


I assume that you will have to format the number yourself. Phone
numbers are very specific to countries.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
I was trying to reproduce the functionality VB6 has. In VB6 you can simply
use:
format("1234567 890","(###) ###-####").

I was wondering if there is something similar in dot net.
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Do you need it for London. Paris, Lyon or for Amsterdam?

To show you that this can be even different for cities.
AS far as I know is this not in the globalization. so you have to write it
yourself however there are lot of samples how to do it by instance for the
US on Internet..

I hope this helps,

Cor
I would like to convert a 10-digit string phone number (1234567890) to say (xxx) xxx-xxxx. Is there a function for this or should I write the code to piece together one character at a time?


Nov 21 '05 #4
Dim Phone As String = "1234567890 "

Label1.Text = Phone.ToString. Format("({0}) {1}-{2}", Phone.Substring (0, 3),
Phone.Substring (3, 3), Phone.Substring (6, 4))

I'n not sure this best way

"KFactor" <kf******@hotma il.com> schreef in bericht
news:Oa******** ******@TK2MSFTN GP15.phx.gbl...
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Any suggestions is appreciated.

Nov 21 '05 #5
KFactor,
Unfortunately .NET does not allow formatting of strings like VB6 does.

In addition to the other comments, what I normally do is convert the phone
number into a number (integer) then use a custom format on the integer.
Something like:

Dim phoneNumber As String = "1234567890 "
phoneNumber = Cint(phoneNumbe r).ToString("(0 00) 000-0000")

Alternatively you might be able to create a ICustomFormatte r object (an
object that implements Syste.ICustomFo rmatter.

Hope this helps
Jay

"KFactor" <kf******@hotma il.com> wrote in message
news:Oa******** ******@TK2MSFTN GP15.phx.gbl...
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Any suggestions is appreciated.

Nov 21 '05 #6
Thanks Jay,

This is exactly what I was looking for.

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OF******** ******@TK2MSFTN GP09.phx.gbl...
KFactor,
Unfortunately .NET does not allow formatting of strings like VB6 does.

In addition to the other comments, what I normally do is convert the phone
number into a number (integer) then use a custom format on the integer.
Something like:

Dim phoneNumber As String = "1234567890 "
phoneNumber = Cint(phoneNumbe r).ToString("(0 00) 000-0000")

Alternatively you might be able to create a ICustomFormatte r object (an
object that implements Syste.ICustomFo rmatter.

Hope this helps
Jay

"KFactor" <kf******@hotma il.com> wrote in message
news:Oa******** ******@TK2MSFTN GP15.phx.gbl...
I would like to convert a 10-digit string phone number (1234567890) to say (xxx) xxx-xxxx. Is there a function for this or should I write the code to piece together one character at a time?

Any suggestions is appreciated.


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2422
by: Sansanee | last post by:
Hi, I am wondering if there is any format string for phone number. Just like those dd:mm:yyyy or C for currency. Can anyone enlighten me? Thank you in advance, Sunny
3
10007
by: deko | last post by:
I have a (Access 2003) contact management database where the user can double-click a contact's phone number in a form and have the Windows Phone Dialer dial the number. The problem is the number has to be in canonical format or dialing rules won't be applied (cf. MSKB Article 318575). I don't want to use an Input Mask because users like to...
2
10815
by: Roxie Aho | last post by:
Using Access 2003. Linked table from SQL Server has phone as 1234567890. Query has phone formatted as (@@@) @@@-@@@@, displaying (123) 456-7890. Data access page is based on the query. Phone field has (@@@) @@@-@@@@ format. It is displaying as 1234567890. How do I get (123) 456-7890 display? Roxie Aho
6
29291
by: Poewood | last post by:
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
3
12504
by: Eddy Soeparmin | last post by:
Hi, How do I apply phone format in a string field? for example (770) 123-1234. Please let me know. Thanks. Eddy
9
4158
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation...
2
18529
by: jeswin12 | last post by:
I used the following script to auto format the phone number field in my form. http://javascript.internet.com/forms/format-phone-number.html The problem with this code is im able to set the auto-format for only one field in the form. Please help me as to how can i make multiple phone fields have this format using this code. Thanks.
6
3672
by: JFB | last post by:
Hi all, How can I format a fax number as 888-333-444? The number is coming from database as 8883334444 <ItemTemplate> <%#container.dataItem("cfax")%> </ItemTemplate> Tks JFB
8
3737
by: Nick | last post by:
Hi there, Membership.GetNumberOfUsersOnline() works great the first time, then jumps up to the number of users registered in the system. I have tried enumerating through each user individually and checking IsOnline which done likewise, first result was 4, then 22 every time after that and it's only be debugging locally using VS. Either...
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.