Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Characters Validation (works with any combination)

String Manipulation

Characters Validation (works with any combination)

by  Malchik  Posted    (Edited  )
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

End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top