positive no

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prp
    New Member
    • Mar 2007
    • 18

    positive no

    I have a textbox in asp.net . and i want to enter only positive number in that text box.I have already used rangevalidator but it takes on -0 without error.please solve the porblem.
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    What values have you given for Maximum value and Minimum Value of Range
    Validator?

    Try for this, Maximum Value=9 and MinimumValue=0

    Comment

    • prp
      New Member
      • Mar 2007
      • 18

      #3
      Originally posted by shweta123
      Hi,

      What values have you given for Maximum value and Minimum Value of Range
      Validator?

      Try for this, Maximum Value=9 and MinimumValue=0
      I gave Minimun Value=0
      Maximum Value=9
      Type =Integer

      But TextBox accept -0 without any error

      Comment

      • radcaesar
        Recognized Expert Contributor
        • Sep 2006
        • 759

        #4
        Refer this buddy,

        http://www.java2s.com/Code/VB/GUI/NumberonlyTextB ox.htm

        :)

        Comment

        • prp
          New Member
          • Mar 2007
          • 18

          #5
          Originally posted by radcaesar
          Refer this buddy,

          http://www.java2s.com/Code/VB/GUI/NumberonlyTextB ox.htm

          :)
          I need the code in asp.net

          Comment

          • SammyB
            Recognized Expert Contributor
            • Mar 2007
            • 807

            #6
            Originally posted by prp
            I have a textbox in asp.net . and i want to enter only positive number in that text box.I have already used rangevalidator but it takes on -0 without error.please solve the porblem.
            But, -0 = 0 and you have set the min =0. If you don't want zero, then set the min = 1. -0 is not negative and it is not positive, it is zero.

            Comment

            • AricC
              Recognized Expert Top Contributor
              • Oct 2006
              • 1885

              #7
              Originally posted by prp
              I have a textbox in asp.net . and i want to enter only positive number in that text box.I have already used rangevalidator but it takes on -0 without error.please solve the porblem.
              You could write a keypress event to only allow numbers in the textbox. You could even do it with Javascript if you don't want to do it server side.

              Comment

              • SaintPatrick
                New Member
                • Feb 2007
                • 9

                #8
                Here's how we can accomplish this easily

                Code:
                Imports System.Text.RegularExpressions
                
                Public Class BlahBlahBlah
                        
                        Private Sub NoNegativeZero()[INDENT] 
                        Dim MyRE As New Regex("^[0-9]+$")
                        Dim MyMatch As Match = MyRE.Match(TextBox1.Text)
                        If MyMatch.Success = False Then
                            MsgBox("I'm not cool with -0")
                        End If
                [/INDENT]
                        End Sub
                
                End Class
                Hope this helps.
                # Anthony Towry

                Comment

                Working...