Did you tried something like this?
Collapse | Copy Code
Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
If allowedChars.IndexOf(e.KeyChar) = -1 Or e.KeyChar = Convert.ToChar(Keys.Back) Then
e.Handled = True
End If
Cheers!