Formatting text boxes

Good Morning,

i have an SQL Server database feeding VB.Net forms, how would i go about formatting a text box to display a telephone number correctly.

Example:
Current: 7054447569 'this is what i currenty have
Formatted:705-444-7569 'this is what i would like to have the output look like

If anyone can help me that would be greatly appreciated

[378 byte] By [Ski_Hard11] at [2007-12-22]
# 1

You'll want to specify a formatting string of something like "000-000-0000" to accomplish this.

How are you setting up your binding or moving of the data from your SQL query to the TextBox?

Worst case if you've got the value in an integer you could simply fire off a:

formattedValue = unformattedValue.ToString("000-000-0000")

I should mention that all of this assumes that you stored this value as a numeric type instead of a string type. If you are starting with a string then you'd need to be a little more manual in your process and do something like this:

formattedValue = string.Format("{0}-{1}-{2}",
unformattedValue.Substring(0, 3),
unformattedValue.Substring(3, 3),
unformattedValue.Substring(6));

BrendanGrant at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

Hi

You can use a MaskedTextBox and assign the mask

YourMaskedControl.Mask = "000-000-000";

Cheers

SalvaPatuel at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified