Solved

Mask Text Control

Posted on 2009-04-09
4
288 Views
Last Modified: 2012-05-06
Hi,

I want a mask input control with the following behaviour...

The user can only enter a floating point number with either two, one, zero signifiacnt digits and up to six digits after the decimal point (this number represents a rate) the user should also be able to enter a minus sign (if required) to represent a negative rate....

How do I acheive this...? Is a "MaskedTextbox" the best way to achieve this..?

Thanks Ian
0
Comment
Question by:ISC
  • 3
4 Comments
 
LVL 15

Expert Comment

by:spprivate
Comment Utility
MaskedTextBox is for passwords or confidential data.
For you you need a regular expression
0
 
LVL 15

Expert Comment

by:spprivate
Comment Utility
I am sorry,my comment about masked text box was wrong.That is a formatter but for you we need to look into regex
0
 
LVL 15

Accepted Solution

by:
spprivate earned 500 total points
Comment Utility
I was in VB 6.0 mode.Here we go
    Public Function IsValid(ByVal Str As String) As Boolean

     

        Dim pattern As String = "^(-)?\d+(\.\d{1,6})?$"

        Dim check As New System.Text.RegularExpressions.Regex(pattern, RegexOptions.IgnorePatternWhitespace)

        Dim valid As Boolean = False

        valid = check.IsMatch(Str)

        Return valid

    End Function
 

    Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave

        If Not IsValid(TextBox1.Text) Then

            MessageBox.Show("Wrong")

            TextBox1.Focus()

            TextBox1.Text = ""
 

        End If
 

    End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:ISC
Comment Utility
Thanks for this I learnt something new...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

17 Experts available now in Live!

Get 1:1 Help Now