Solved

Validating Masked Textboxes

Posted on 2008-10-12
3
446 Views
Last Modified: 2012-05-05
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
Comment
Question by:Mr_Fulano
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 22698878
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 22698886
Hi Fulano,
You can use MaskCompleted to validate you field
If Me.MaskedTextBox1.MaskCompleted Then
    ' valid field
End If
0
 

Author Closing Comment

by:Mr_Fulano
ID: 31505489
Good suggestions. This is what I needed to do. - Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now