Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Validating Masked Textboxes

Hi I'm using VB 2005, WinForms. I need to validate a Masked TextBox that I have on my Form, which is formatted for telephone numbers [i.e. (999) 000-0000]. If I try to determine the length of the textbox's text property using "myMaskedTextBox.Text.Trim.Length", I get a value of 10 on an empty phone number (empty meaning no numbers entered). I assume the masking characters are being considered as part of the overall length, so how do I count the number of actual "numbers" in the textbox? I need there to be a total of 10 valid digits in the field before it is accepted as a complete and accurate phone number.  

Any suggestions?

Thanks,
Fulano
If myMaskedTextBox.Text.Trim.Length < 10 Then
   Console.WriteLine("Not a valid phone number")
End If

Open in new window

0
Mr_Fulano
Asked:
Mr_Fulano
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
set the TextMaskFormat property to ExcludePromptAndLiterals

see http://www.emoreau.com/Entries/Articles/2006/06/The-TextBox-and-the-MaskedTextbox-controls.aspx for details
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Hi Fulano,
You can use MaskCompleted to validate you field
If Me.MaskedTextBox1.MaskCompleted Then
    ' valid field
End If
0
 
Mr_FulanoAuthor Commented:
Good suggestions. This is what I needed to do. - Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now