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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check string for characters other than 0-9 and a-z 2

Status
Not open for further replies.

rtshort

IS-IT--Management
Joined
Feb 28, 2001
Messages
878
Location
US
What is the best way to check a string for characters other than 0-9 or a-z(Upper or Lower Case). I know about the InStr Function but that would be a lot of code. I don't want to allow characters like (!@#$%^&*()_+) in the string.
Just letters and numbers. Rob
Just my $.02.
 
Hi,

what about getting the ASCII-Value of the character and
compare it to the range of a-z,A-Z and 0-9
(I think the ASCII-Code (dez) is 48 (0) to 57 (9), 65 (A) to 90 (Z) and 97 (a) to 122 (z)).

At is time i don't know another solution. I' ll post, if i got a new idea or found some code.

Cu,
Daniel
---------------------------------------
Visit me @:
 
Function IsStrAZ909(strIn As string) As boolean
Dim I as Long
For I = 1 To Len(strIn)
if Not(Mid$(strIn,I,1) Like "[a-zA-Z0-9]") Then
IsStrAZ09 = false
Exit Function
End if
Next
IsStrAZ09 = True
End Function Compare Code (Text)
Generate Sort in VB or VBScript
 
Thanks guys, I'll try both.
Rob
Just my $.02.
 
Okay, i think JohnYingling's solution is "smarter" - but i also got one - jehaa ;-) - Here it is:

Option Explicit

Private Sub Text1_KeyPress(keyascii As Integer)
keyascii = justnumbersandchar(keyascii)

End Sub

Function justnumbersandchar(keyascii As Integer)

Const Nummern$ = "0123456789"
Const Zeichen$ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
If (InStr(Nummern, Chr(keyascii)) <> 0 Or _
InStr(Zeichen, Chr(keyascii)) <> 0) = False Then keyascii = 0
justnumbersandchar = keyascii

End Function
---------------------------------------
Visit me @:
 
They both work, but I can't figure out how to get it in a .bas module where I can use it without typing all of the code for each TextBox. Anyone?
Rob
Just my $.02.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top