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
  1. Home
  2. Web Development
  3. ASP.NET
  4. asp.net keypress event

asp.net keypress event

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netregextutorialquestion
5 Posts 5 Posters 1 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.
  • B Offline
    B Offline
    berba
    wrote on last edited by
    #1

    I want validation for text box in a text box enter only whole numbers(no decimal). The keypress event is not available in ASP.Net. How to get key press event? Can it be done using regular expression validator? Cheers Berba

    S K N M 4 Replies Last reply
    0
    • B berba

      I want validation for text box in a text box enter only whole numbers(no decimal). The keypress event is not available in ASP.Net. How to get key press event? Can it be done using regular expression validator? Cheers Berba

      S Offline
      S Offline
      StianSandberg
      wrote on last edited by
      #2

      ASP.NET is serverside. You will have to use javascript. JQuery validation is a good plave to start :) --------------- stian.net

      1 Reply Last reply
      0
      • B berba

        I want validation for text box in a text box enter only whole numbers(no decimal). The keypress event is not available in ASP.Net. How to get key press event? Can it be done using regular expression validator? Cheers Berba

        K Offline
        K Offline
        ksvinothmca
        wrote on last edited by
        #3

        yes you can use regular expression ie) [^0-9].

        1 Reply Last reply
        0
        • B berba

          I want validation for text box in a text box enter only whole numbers(no decimal). The keypress event is not available in ASP.Net. How to get key press event? Can it be done using regular expression validator? Cheers Berba

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You can use a MaskedEdit textbox and set the mask to only accept numbers. No validation or event handling needed.


          No comment

          1 Reply Last reply
          0
          • B berba

            I want validation for text box in a text box enter only whole numbers(no decimal). The keypress event is not available in ASP.Net. How to get key press event? Can it be done using regular expression validator? Cheers Berba

            M Offline
            M Offline
            Morgs Morgan
            wrote on last edited by
            #5

            Use a javascript/jquery function to achieve this: 1. HTML Mockup

            Above, "onkeypress" is the client-side keypress event. For more accuracy, you could replace "onkeypress" with "onkeyup" which only fires when you let go of a "key" (on your keyboard). 2. Javascript/jQuery

            function Validate( sender )
            {
            if( parseInt( sender.val() ) )
            {
            //proceed with the intended operation
            }
            else
            {
            alert( 'Sorry, only whole numbers are allowed in this input field. Please try again.' );
            }
            }

            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