Solved

Validating Masked Textboxes

Posted on 2008-10-12
3
445 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
Comment Utility
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
Comment Utility
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
Comment Utility
Good suggestions. This is what I needed to do. - Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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