473,836 Members | 1,935 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 17953
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
2443
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
10038
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 put comments after the number, like: "985-983-0098 ext. 980 - Mike B." I thought there might be a...
2
10831
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
29329
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
12516
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
4184
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 (e.g. this is numeric, this is alpha-numeric, etc.)
2
18568
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
3681
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
3778
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 I'm doing something seriously wrong or this function is a
0
9656
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10819
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10570
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10240
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9355
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6972
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5641
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4438
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
3
3100
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.