Input value integer alone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PerumalSamy
    New Member
    • Feb 2007
    • 64

    Input value integer alone

    Hi all , How can we restrict user to enter integer alone in textbox (like using ascii code restriction in keypress event in VB).

    since keypress event not available for textbox property in asp.net 1.1 how can we overcome this problem
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by PerumalSamy
    Hi all , How can we restrict user to enter integer alone in textbox (like using ascii code restriction in keypress event in VB).

    since keypress event not available for textbox property in asp.net 1.1 how can we overcome this problem
    I'm sure there is some JavaScript out there that will do this for you. I know that there is an extender that comes with the ASP.NET AJAX package that filters text boxes for you and will not accept user input that isn't a number... but to use you will require .NET Framework 2 or higher to run it...and of course download ASP.NET Ajax.

    If you are restricted to only using VB, I'd suggest letting the user enter whatever they would like to and then displaying an error message stating that they are only allowed to enter numbers as a valid input value.

    You could also use a RegularExpressi onValidator that checks to see if numbers have been entered into the Textbox. This will not prevent the user from entering other values in the textbox but will catch the error before it is submitted to the server

    Remember that the RegularExpressi onValidator (as well as the other validation tools that come with Visual Studio) use JavaScript to do the checking for you.

    Hope this helps

    -Frinny

    Comment

    • dotneto
      New Member
      • Feb 2007
      • 36

      #3
      Originally posted by Frinavale
      I'm sure there is some JavaScript out there that will do this for you. I know that there is an extender that comes with the ASP.NET AJAX package that filters text boxes for you and will not accept user input that isn't a number... but to use you will require .NET Framework 2 or higher to run it...and of course download ASP.NET Ajax.

      If you are restricted to only using VB, I'd suggest letting the user enter whatever they would like to and then displaying an error message stating that they are only allowed to enter numbers as a valid input value.

      You could also use a RegularExpressi onValidator that checks to see if numbers have been entered into the Textbox. This will not prevent the user from entering other values in the textbox but will catch the error before it is submitted to the server

      Remember that the RegularExpressi onValidator (as well as the other validation tools that come with Visual Studio) use JavaScript to do the checking for you.

      Hope this helps

      -Frinny
      Hi, I think the best way is to use regular expression validator, something like \d* will do it i guess.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by dotneto
        Hi, I think the best way is to use regular expression validator, something like \d* will do it i guess.

        Just remember that there are ways around this validator because its javascript. You should do a server side check as well if you want to be sure your user input is correct...its not hard to do a Integer.Parse(i nput) in a try catch.

        Happy Coding
        :)
        -Frinny

        Comment

        Working...