Take the 2-minute tour ×

How i can make this condition en VB.NET

If e.KeyCode = [a-zA-Z0-9] Then
End if

I have understood that the Keycode are numbers but as I can do this validation with regex?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Try this:

        Dim reg_exp As New Regex("[a-zA-Z0-9]")
        If reg_exp.IsMatch(e.KeyCode.ToString) Then
        End If
share|improve this answer
wow great solution! –  John Nuñez Mar 28 '12 at 18:13
add comment

You can use .Net's Char.IsLetterOrDigit, which also allows Unicode characters:

Example: http://ideone.com/7ykE0

share|improve this answer
add comment

Your Answer


