CodeItBetter Programming Another VB Programming Blog

How to Make a TextBox allow only letters and numbers

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'Controls - How to Make a TextBox allow only letters and numbers
'In the TextBox's KeyPress event, look for characters that are not letters or
'numbers and discard them by setting KeyAscii to 0.

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case Is < 32            ' Control keys are OK.
    Case 48 To 57           ' This is a digit.
    Case 65 To 90           ' Characters A to Z
    Case 97 To 122          ' Characters a to z
    Case Else               ' Reject any other key.
        KeyAscii = 0
    End Select
End Sub

Related posts:

  1. How to allow only number in a text box
  2. How to allow only number and only one occurence of decimal character in text box
  3. How to Prevent the user from entering invalid keys in a text box.
  4. How to Ignore Specific Characters in TextBox
  5. How to control what type of alphanumeric character is entered into a text box at a particular postion in the text box.
  6. How to disable beep when user presses the Enter key in TextBox
  7. How to convert Numbers to words i.e., 44 = fourty four
  8. How to convert textbox content to uppercase
  9. How to edit an MSFlexgrid
  10. How to enter text in MSFlex Grid control without using text box.

Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.