Const sValidLetter As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const sValidNumeric As String = "0123456789"
Const sValidFrench As String = "TOFaTG(÷v·t"
Public Enum eCaseCheck
eUPPER = 0
eLOWER = 1
eBOTH = 2
End Enum
Private Sub Text1_KeyPress(KeyAscii As Integer)
'Check with space, letters and french accents no case sensitivity
If Not isValidChar(KeyAscii, Chr(32) + sValidLetter + sValidFrench, eBOTH) Then KeyAscii = 0
End Sub
Public Function isValidChar(KeyAscii As Integer, sValidKey As String, iCheck As eCaseCheck) As Boolean
'Backspace or Enter
If KeyAscii = 8 Or KeyAscii = 13 Then
isValidChar = True
Exit Function
End If
If iCheck = eLOWER Then
isValidChar = InStr(1, LCase(sValidKey), Chr(KeyAscii)) > 0
ElseIf iCheck = eUPPER Then
isValidChar = InStr(1, UCase(sValidKey), Chr(KeyAscii)) > 0
Else
isValidChar = InStr(1, UCase(sValidKey), UCase(Chr(KeyAscii))) > 0
End If
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.