|
-
Apr 14th, 2006, 02:31 AM
#1
Thread Starter
Addicted Member
[RESOLVED] check for certain characters in a string
How can i check, in a string, so that the only a string can contain, "." and ":", and "a-z/A-Z", and "0-9" are allowed, and the strings with other characters such as !@#$%^&*(){};'"/?<>|¢£¤¥ and so on are ignored?
-
Apr 14th, 2006, 03:55 AM
#2
Re: check for certain characters in a string
there might be better ways,
VB Code:
Private Function IsStringOk(strString As String) As Boolean
Dim i As Integer
Dim strS As String
For i = 48 To 57
strS = strS & Chr$(i)
Next i
For i = 65 To 90
strS = strS & Chr$(i)
Next i
For i = 97 To 122
strS = strS & Chr$(i)
Next i
Debug.Print strS
For i = 1 To Len(strString)
If Not InStr(1, strS, Mid$(strString, i, 1)) > 0 Then
IsStringOk = False
Exit Function
End If
Next i
IsStringOk = True
End Function
Private Sub Command1_Click()
If Not IsStringOk("abc?") Then MsgBox "notOk"
End Sub
-
Apr 14th, 2006, 08:06 AM
#3
Re: check for certain characters in a string
VB Code:
Public Function RemoveInvalidChars(ByVal InputStr As String) As String
Dim i As Integer
dim sTemp As String
sTemp = InputStr
For i = 0 to 255 'or greater, i based on 255 ascii
Select Case i
Case 48 To 57, 65 To 90, 97 To 122
'skip
Case Else 'replace these characters with ""
sTemp = Replace(sTemp, Chr(i), "", vbBinaryCompare)
End Select
Next
RemoveInvalidChars = sTemp
End Function
-
Apr 14th, 2006, 01:31 PM
#4
Thread Starter
Addicted Member
Re: check for certain characters in a string
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|