Solved

Mask Text Control

Posted on 2009-04-09
4
300 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
ID: 24108692
MaskedTextBox is for passwords or confidential data.
For you you need a regular expression
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24108773
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
ID: 24109216
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
ID: 31568604
Thanks for this I learnt something new...
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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

20 Experts available now in Live!

Get 1:1 Help Now