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. General Programming
  3. Visual Basic
  4. Limiting textbox input to numbers

Limiting textbox input to numbers

Scheduled Pinned Locked Moved Visual Basic
questioncom
3 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.
  • F Offline
    F Offline
    Fredrik Skog
    wrote on last edited by
    #1

    I have got a textbox that I want to limit to numerical values. How do I prevent the user from entering text? I have set the DataFormat property to "Number", but that doesn't do it. Cheers, Fredrik
    Sonork ID: 100.11430:PhatBoy

    'It is so much simpler to bury reality than it is to dispose of dreams.'
    - Don Delillo, Americana

    H 1 Reply Last reply
    0
    • F Fredrik Skog

      I have got a textbox that I want to limit to numerical values. How do I prevent the user from entering text? I have set the DataFormat property to "Number", but that doesn't do it. Cheers, Fredrik
      Sonork ID: 100.11430:PhatBoy

      'It is so much simpler to bury reality than it is to dispose of dreams.'
      - Don Delillo, Americana

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Hi.. Try this: add an event handler to the KeyPress event of the text box: Private Sub text1_KeyPress(KeyAscii As Integer) If Not (KeyAscii > 47 And KeyAscii < 59) Then KeyAscii = 0 End If End Sub the code above checks the ascii code of the character and validates the range and sets it to 0 if out of the range of numbers.

      L 1 Reply Last reply
      0
      • H Hesham Amin

        Hi.. Try this: add an event handler to the KeyPress event of the text box: Private Sub text1_KeyPress(KeyAscii As Integer) If Not (KeyAscii > 47 And KeyAscii < 59) Then KeyAscii = 0 End If End Sub the code above checks the ascii code of the character and validates the range and sets it to 0 if out of the range of numbers.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The Above given code does not work VB.NET so can u plz suggest me something else :)

        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