How to search a textbox for numbers, and if numbers not found give error messege

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srig
    New Member
    • Feb 2009
    • 11

    How to search a textbox for numbers, and if numbers not found give error messege

    hi every one..
    i need to get id as input..wen d user gives input other than numbers like alphabets or special characters then it should display error message..isnume ric wil work in vb.net.. but i m workin in visual studio 2005.. can any one help me in this

    regards
    sri
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Have you tried using regular expressions?

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Regular expressions are very powerful and can easily check if a String contains a number. You should really look into using them. They can be used in your server side .NET code and can also be used by client side scripting languages like JavaScript.

      There is a RegularExpressi onValidator control that can check your TextBox value before the page is submitted to the server (it uses JavaScript to do this validation). It is strongly advisable to also check this on the server because there are ways around the client side validation.

      Check out this article on how to check if a TextBox contains a number. At this time, this article does not cover how to use regular expressions or the RegularExpressi onValidator but in the future it may be updated to include this topic.

      Cheers,

      -Frinny

      Comment

      • amirghaffarie1362
        New Member
        • Jan 2009
        • 19

        #4
        this BOLD javascript code lock keyword , so users just could inter Number in text box

        <asp:TextBox onkeypress=" if((event.keyCo de>57) || (event.keyCode< 48)) {event.returnVa lue=false}" id="TextBoxAmou nt" runat="server" ></asp:TextBox>

        Comment

        • srig
          New Member
          • Feb 2009
          • 11

          #5
          thanks frinny:)
          i got it..it helped me a lot and learnt new things..
          thank u very much:)

          Regards
          Sri

          Comment

          Working...