-
I am trying to validate a text box I only want numbers and the letters a – f. I can’t have any other characters. I tried a sub with some if then statements, also I tried the key press event, but the invalid character still gets passed to the variable. How do I validate this text box?
Thanks
Bryan
-
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then 'this means it's a number
ElseIf KeyAscii >= 65 And KeyAscii <= 70 Then
'this means it's a capital letter
ElseIf KeyAscii >= 97 And KeyAscii <= 102 Then
'this means it's a lower case letter
Else
KeyAscii = 0 'it won't write anything to the text box.
'this means it's a different character
End If
End Sub
That should work just fine.