473,545 Members | 2,048 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 17890
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
7415
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
7928
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...
1
7440
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
5997
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...
1
5344
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
4963
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
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.