Mr_Fulano
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
Any suggestions?
Thanks,
Fulano
If myMaskedTextBox.Text.Trim.Length < 10 Then
Console.WriteLine("Not a valid phone number")
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good suggestions. This is what I needed to do. - Thanks!
You can use MaskCompleted to validate you field
If Me.MaskedTextBox1.MaskComp
' valid field
End If