Solved

Validating Masked Textboxes

Posted on 2008-10-12
3
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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