Pirahnaplant
Well-known member
- Joined
- Mar 29, 2009
- Messages
- 75
- Programming Experience
- 3-5
How can I make a text box only accept certain characters?
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar < Chr(49) Or e.KeyChar > Chr(53) Then e.Handled = True
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Select Case e.KeyCode
Case Keys.A, Keys.B, Keys.C
'allowed
Case Else
'not allowed
e.SuppressKeyPress = True
End Select
End Sub