473,597 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 29299
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*****@discus sions.microsoft .com> wrote in message
news:37******** *************** ***********@mic rosoft.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*****@discus sions.microsoft .com> wrote in message
news:37******** *************** ***********@mic rosoft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
19216
by: joemono | last post by:
Hello everyone! First, I appologize if this posting isn't proper "netiquette" for this group. I've been working with perl for almost 2 years now. However, my regular expression knowledge is pretty limited. I wrote the following expression to take (hopefully) any _reasonable_ phone number input, and format it as (999) 999-9999 x 9999.
5
3513
by: Kamaluokeakua | last post by:
I have to write an application that deals with clients in multiple countries. The addresses, phone numbers, country id and currency information has to be stored into a database that allows for the format of any country. I would like to be able to automatically display the information in the format of their country based on the information gathered from the Country field in the database. Is there any white paper, or book or site that has...
3
2915
by: Mike | last post by:
I need to update a table with a phone number and have the phone number like (800)555-1212 how can I put ( ) around the area code in the update process?
6
17910
by: KFactor | last post by:
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.
4
4539
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
1
3356
by: womblesjc | last post by:
I have a data bound Details View control in asp.net 2.0 that formats a phone number. The 'Default Mode' for the control is set to Edit. The phone number field is a template field and I can successfully call a function that formats the phone number when the control is filled. But when updating, the value being passed in to my format function is vbNull instead of the value in the phone number field of the control. How can I get the update...
10
14290
by: JackM | last post by:
I'm still working on validating the phone numbers that are entered on a form but have come across a problem I don't understand how to fix. I can handle most instances when it's in regular US formats (555-555-5555 or (555) 555-5555 or 555 555 5555) but I'm having trouble when the entry is ten consecutive numbers with nothing else (5555555555). Not only does it not validate, but it shows as 2147483647 when I call the variable to check to see...
2
18539
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.
4
5045
by: luke noob | last post by:
This is my HTML... <head> <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script> <script type="text/javascript" src="js/script.js"></script> </head> <body>
0
7965
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7885
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
8271
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...
0
8380
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8031
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
8258
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
6686
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
5426
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
3881
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...

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.