Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format mskphone

Status
Not open for further replies.

brews

Technical User
Dec 12, 2007
194
US
Trying to make sure that a mask text box is filled correctly. Tried this with no luck:

Code:
If mskPhone.Text <> "(xxx) xxx-xxxx" Then
                MessageBox.Show("Please enter phone data in this format 'xxx xxx-xxxx'", "Wrong Fromat", MessageBoxButtons.OK, MessageBoxIcon.Error)
       Exit Sub
 End If
No matter if the entry is 'x xxx-xxxx' or 'xxx xxx-xxxx' the code throws an error.

Thanks for the help.
 
Use the Mask property of the MaskedTextBox:

mskPhone.Mask = "(999) 000-0000"

Or just click on the Mask property in the Properties list, click the browse button and select "Phone number" from the list of predefined masks.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks for the response. I already have that which does not resolve the issue when someone enters 26 555-1212.
 
Looks to me like the area code is not required in masked text box.

But try this logic:

Code:
If Not mskPhone.MaskCompleted Or Strings.InStr(Strings.Left(mskPhone.Text, 5), " ") Then
    MessageBox.Show("Please enter phone data in this format 'xxx xxx-xxxx'", "Wrong Fromat", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thank you. That works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top