This blog describes how to restrict the user's input to letters only, numbers only, letters or numbers only, and special characters only.
Letters only
The below code is restricted to allow only text to be entered into the TextBox.
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsLetter(e.KeyChar) Then
e.Handled = True
End If
End Sub
Numbers only
The below code is restricted to allow only text to be entered into the TextBox.
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsNumber(e.KeyChar) Then
e.Handled = True

Join the conversation! Your thoughts help the community grow.