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. General Programming
  3. Visual Basic
  4. Easy, simple way to make a textbox only accept numeric, or alpha chars?????

Easy, simple way to make a textbox only accept numeric, or alpha chars?????

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
4 Posts 2 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.
  • J Offline
    J Offline
    Joey Picerno
    wrote on last edited by
    #1

    I have read some of the articles on this site and others reguarding this issue and all of them involve custom controls or writing a class to accomplish this simple task. Someone has got to know a simple easy way to accomplish this with a few lines of code. I mean VB6 had this property for the textboxes but .NET doesnt and you have to make a custom control or write a class??? This doesnt make any sense. If anyone knows of a simple way to make a textbox accept ONLY numeric and ONLY alpha, please let me know. Thank you in advance.

    N 1 Reply Last reply
    0
    • J Joey Picerno

      I have read some of the articles on this site and others reguarding this issue and all of them involve custom controls or writing a class to accomplish this simple task. Someone has got to know a simple easy way to accomplish this with a few lines of code. I mean VB6 had this property for the textboxes but .NET doesnt and you have to make a custom control or write a class??? This doesnt make any sense. If anyone knows of a simple way to make a textbox accept ONLY numeric and ONLY alpha, please let me know. Thank you in advance.

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      pass the 'e' argument of the keypress event of the textbox into either routine: Public Sub KeyPress_Numeric_Only(ByVal e As System.Windows.Forms.KeyPressEventArgs) Select Case Asc(e.KeyChar) Case Keys.Back, Keys.D0 To Keys.D9 'continue Case Else e.Handled = True End Select End Sub Public Sub KeyPress_Alpha_Only(ByVal e As System.Windows.Forms.KeyPressEventArgs) Select Case Asc(UCase(e.KeyChar)) Case Keys.Back, Keys.A To Keys.Z 'continue Case Else e.Handled = True End Select End Sub

      J 1 Reply Last reply
      0
      • N nlarson11

        pass the 'e' argument of the keypress event of the textbox into either routine: Public Sub KeyPress_Numeric_Only(ByVal e As System.Windows.Forms.KeyPressEventArgs) Select Case Asc(e.KeyChar) Case Keys.Back, Keys.D0 To Keys.D9 'continue Case Else e.Handled = True End Select End Sub Public Sub KeyPress_Alpha_Only(ByVal e As System.Windows.Forms.KeyPressEventArgs) Select Case Asc(UCase(e.KeyChar)) Case Keys.Back, Keys.A To Keys.Z 'continue Case Else e.Handled = True End Select End Sub

        J Offline
        J Offline
        Joey Picerno
        wrote on last edited by
        #3

        is this going to work for the seperate keypad as well??? (keypad on the right of keyboard...

        N 1 Reply Last reply
        0
        • J Joey Picerno

          is this going to work for the seperate keypad as well??? (keypad on the right of keyboard...

          N Offline
          N Offline
          nlarson11
          wrote on last edited by
          #4

          sorry: Public Sub KeyPress_Numeric_Only(ByVal e As System.Windows.Forms.KeyPressEventArgs) Select Case Asc(e.KeyChar) Case Keys.Back, Keys.D0 To Keys.D9,keys.numpad0 to keys.numpad9 'continue Case Else e.Handled = True End Select End Sub

          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