Standard Character Validation (1 Viewer)

clive2002

Registered User.
Local time
Today, 05:52
Joined
Apr 21, 2002
Messages
91
Anyone now a quick way to return whether a string contains only standard characters (A-Z,a-z,0-9) as a true/false.
 

namliam

The Mailman - AWF VIP
Local time
Today, 06:52
Joined
Aug 11, 2003
Messages
11,695
Try this:
Code:
Function TrueChars(myString As String) As Boolean
Dim I As Integer
TrueChars = True
For I = 1 To Len(myString)
    Select Case Asc(Mid(myString, I, 1))
        Case 48 To 57  '0 to 9
        Case 65 To 90  'A to Z
        Case 97 To 122 'a to z
        Case Else
            TrueChars = False
            Exit For
    End Select
Next I
End Function
(partly borrowed from Jason to make me look smart ;) )

Regards
 

SilentBreaker

Registered User.
Local time
Today, 05:52
Joined
Aug 7, 2003
Messages
28
This is an immediate example:

Private Sub Text0_KeyPress(KeyAscii As Integer)

If KeyAscii >= 65 And KeyAscii <= 90 Or KeyAscii >= 97 And KeyAscii <= 122 Then
MsgBox "True"
Else
MsgBox "False"
End If

End Sub

Cheers :)
 

clive2002

Registered User.
Local time
Today, 05:52
Joined
Apr 21, 2002
Messages
91
This Works, but i forgot i need to allow a space aswell!

how do i refer to this!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:52
Joined
Feb 19, 2002
Messages
43,424
A quick way (as long as you have the VBA window open) to find ascii values is to use the asc() function -

print asc(" ") - will print 32

you can go the other way with -

print chr(32) - which will print an empty line. Unprintable characters will print as ''.
 

Users who are viewing this thread

Top Bottom