You can just make a string full of them and check to make sure that that char isnt in the String. Simple.
Code:
Dim invalidChars As String = "0123456789"
Private Sub TextBox1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If invalidChars.IndexOf(e.KeyChar) >= 0 Then e.Handled = True
End Sub
Also, try looking into the Char class. It has a lot of useful methods for evaluating characters that may save you a lot of code. For example, to accept only digits or letters, you can do this:
Private Sub TextBox1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.