Link to home
Start Free TrialLog in
Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Fulano,
You can use MaskCompleted to validate you field
If Me.MaskedTextBox1.MaskCompleted Then
    ' valid field
End If
Avatar of Mr_Fulano

ASKER

Good suggestions. This is what I needed to do. - Thanks!