Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Mask Text Control

Posted on 2009-04-09
4
Medium Priority
?
335 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
[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
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 2000 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

Technology Partners: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

609 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