How to validate textbox accept only negative float numbers in .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishnaneeraja
    New Member
    • Mar 2008
    • 21

    How to validate textbox accept only negative float numbers in .net

    Hi,

    Iam developing windows application using vb.net with c#.net.In this i want to validate textbox accept only negative float numbers like -2.3 etc....
    please help me.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What have you tried so far?

    Comment

    • madankarmukta
      Contributor
      • Apr 2008
      • 308

      #3
      HI,
      You can use regular expression for this.. This is very effective to validate the any input from the user.

      Thanks!

      Comment

      • cloud255
        Recognized Expert Contributor
        • Jun 2008
        • 427

        #4
        A try catch statement trying to parse the input to a float will allow you to check if the number is a float. Then just multiply by -1 and see if the result is less than 0.

        Comment

        • jodi
          New Member
          • Feb 2007
          • 5

          #5
          is this a windows app?

          if it is, then you need to do something like this in the OnTextChanged event:

          decimal dec;

          decimal.TryPars e(this.Text, out dec);

          if (dec < 0)
          Ok
          else
          whatever

          if you want to put a mask on your textbox, you can try several there are in the net to be downloaded

          tried google and the first seems to do what you want
          http://www.csharphelp. com/archives2/archive305.html

          cya

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            It would probably be overkill, but there is a MaskedTextBox class in .NET for windows applications that could be used.

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              How do you develop an app using "vb.net with C#.net"?

              Comment

              Working...