Solved

Mask Text Control

Posted on 2009-04-09
4
310 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get size of each directory on each mapped drive 5 29
VB.Net - KeyPress Event 4 37
write xml in vb.net 2 24
Obtain cell value using column ID in DataGrid using VB.NET 2 23
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 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