Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Allow numericals in text box for an application in ASP.net and C#

Allow numericals in text box for an application in ASP.net and C#

Scheduled Pinned Locked Moved ASP.NET
csharpasp-net
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sajitk20
    wrote on last edited by
    #1

    Dear All, I am making an application using ASP.Net and C#. I have a text box where i require only numerics to be entered.... I have used the RegularExpressionValidator. I there any other way, where we can trap the Ascii key of the key pressed and validate this. Thanks in advance Sajit :)

    S C 2 Replies Last reply
    0
    • S sajitk20

      Dear All, I am making an application using ASP.Net and C#. I have a text box where i require only numerics to be entered.... I have used the RegularExpressionValidator. I there any other way, where we can trap the Ascii key of the key pressed and validate this. Thanks in advance Sajit :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can do this using javascript, but you should still use a validator on the server side, just in case. All JS can be defeated.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • S sajitk20

        Dear All, I am making an application using ASP.Net and C#. I have a text box where i require only numerics to be entered.... I have used the RegularExpressionValidator. I there any other way, where we can trap the Ascii key of the key pressed and validate this. Thanks in advance Sajit :)

        S Offline
        S Offline
        sashidhar
        wrote on last edited by
        #3

        Try this Link It May Help http://rizwanshah.blogspot.com/2008/07/numeric-textbox-aspnet-html-input.html[^]

        MyFirstArticle MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

        S 1 Reply Last reply
        0
        • S sashidhar

          Try this Link It May Help http://rizwanshah.blogspot.com/2008/07/numeric-textbox-aspnet-html-input.html[^]

          MyFirstArticle MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

          S Offline
          S Offline
          sajitk20
          wrote on last edited by
          #4

          Dear Sasidhar, Thanks for the fast response. But the msdn link is for a window application. I am sorry, but i am making a web application. Can you throw some light on it. Sajit

          S 1 Reply Last reply
          0
          • S sajitk20

            Dear Sasidhar, Thanks for the fast response. But the msdn link is for a window application. I am sorry, but i am making a web application. Can you throw some light on it. Sajit

            S Offline
            S Offline
            sashidhar
            wrote on last edited by
            #5

            Again Try Now I modified It

            MyFirstArticle MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

            S 1 Reply Last reply
            0
            • S sashidhar

              Again Try Now I modified It

              MyFirstArticle MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

              S Offline
              S Offline
              sajitk20
              wrote on last edited by
              #6

              Dear sashidhar, where is the link...?? do i follow the same rizwan blog link... sajit

              S 1 Reply Last reply
              0
              • S sajitk20

                Dear sashidhar, where is the link...?? do i follow the same rizwan blog link... sajit

                S Offline
                S Offline
                sashidhar
                wrote on last edited by
                #7

                <
                script language="javascript">
                function KeyCheck(e)
                {
                var KeyID = (window.event) ? event.keyCode : e.which;
                if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) ||
                (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
                {
                return false;
                }
                return true;
                }
                </
                script>
                HTML Text Box
                <
                input type="text" ID="txt_TextBox" onkeypress="return KeyCheck(event);" runat="server" style="width: 28px" />
                ASP.Net TextBox
                <asp:TextBox ID="txt_ASPTextBox" runat="server" ></asp:TextBox>
                Code Behind for Asp.Net TextBox
                txt_ASPTextBox.Attributes.Add("onkeypress","return KeyCheck(event);");

                I Think This Your Answer..! If ITs Not Sorry..1

                MyFirstArticle MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups