473,581 Members | 2,444 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 17907
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
2427
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
10013
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
10819
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
29298
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
12507
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
4161
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
18537
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
3674
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
3746
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
7788
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
8137
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. ...
1
7890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8163
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...
0
6545
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5355
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
3813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2297
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
1
1397
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.