-
Hi,
I a, trying to fill out a web form using the inet control
and the login name only supports a-z, 0-9, - and _ characters. I was just wondering if there was a shorter wat to do this than what I have done, I know it can be done in the keypress event, but it is not to check the text until a command button is pressed so this is the code:
Code:
Dim i As Long
For i = 1 To Len(Text1)
If Mid$(Text1, i, i) = "a" Or Mid$(Text1, i, i) = "b" Or Mid$(Text1, i, i) = "c" Or Mid$(Text1, i, i) = "d" Or Mid$(Text1, i, i) = "e" Or Mid$(Text1, i, i) = "f" Or Mid$(Text1, i, i) = "g" Or Mid$(Text1, i, i) = "h" Or Mid$(Text1, i, i) = "i" Or Mid$(Text1, i, i) = "j" Or Mid$(Text1, i, i) = "k" Or Mid$(Text1, i, i) = "l" Or Mid$(Text1, i, i) = "m" Or Mid$(Text1, i, i) = "n" Or Mid$(Text1, i, i) = "o" Or Mid$(Text1, i, i) = "p" Or Mid$(Text1, i, i) = "q" Or Mid$(Text1, i, i) = "r" Or Mid$(Text1, i, i) = "s" Or Mid$(Text1, i, i) = "t" Or Mid$(Text1, i, i) = "u" Or Mid$(Text1, i, i) = "v" Or Mid$(Text1, i, i) = "w" Or Mid$(Text1, i, i) = "x" Or Mid$(Text1, i, i) = "y" Or Mid$(Text1, i, i) = "z" Or Mid$(Text1, i, i) = "1" Or Mid$(Text1, i, i) = "2" Or Mid$(Text1, i, i) = "3" Or Mid$(Text1, i, i) = "4" Or Mid$(Text1, i, i) = "5" Or Mid$(Text1, i, i) = "6" Or Mid$(Text1, i, i) = "7" Or Mid$(Text1, i, i) = "8" Or Mid$(Text1, i, i) = "9" Or Mid$(Text1, i, i) = "0" Or Mid$(Text1, i, i) = "-" _
Or Mid$(Text1, i, i) = "_" Then
Else
MsgBox "Invalid Character in Login Name", vbExclamation, "Error"
Exit Sub
End If
Next i
-
lol I just found out the code I wrote to do that doesn't even work, lol it gives an error for most characters even the ones it is supposed to allow. anyone got a better code? and can tell me what is wrong with mine.
thanx.
-
ok I see my dumb ass mistake now the length property int he mid$ should have been 1 instead of i.
-
Well, that's an odd effect. Trying to reply to this post made my field entry boxes disappear.
Crypt: Try something like this:
Code:
Dim i As Long
Dim a as String
For i = 1 To Len(Text1)
a=Mid$(Text1,i,1)
If IsNumeric(a) or a="-" or a="_" or (Asc(a)>96 and Asc(a)<123) Then
Else
MsgBox "Invalid Character in Login Name", vbExclamation, "Error"
Exit Sub
End If
Next i
-
lol it made mine empty posting replies too, it because my code goes along long way over that >>> way seing as I was taking every character into account that is pushed everything over a bit lol.
Anyways thanx for the code Andrew code works great :D
-
try this
Dim i As Long
Dim blnOK as boolean
dim s as string
'This will be the allowed characters
s ="abcdefghijklmnop.....09123...._"
blnOK = True
For i = 1 To Len(Trim$(Text1))
If InStr(1, s, Mid$(Trim$(Text1), i, 1)) = 0 Then blnOK = False
Next i
if blnOK = false then
MsgBox "Invalid Character",vbExclamation, "Error"
Exit Sub
End If
-
Another method....
Code:
Public Function ValidateString(ByVal strTest As String, ByVal MaxChars As Integer) As Boolean
ValidateString = True
If Len(strTest) > MaxChars Then
ValidateString = False
MsgBox "String cannot exceed " & MaxChars & " characters"
Exit Function
End If
For i = 1 To Len(strTest)
j = Mid(strTest, i, 1) Like "[!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789()_]"
If j Then
ValidateString = False
MsgBox "Name contains invalid characters"
Exit Function
End If
Next i
End Function
[Edited by Judd on 07-05-2000 at 06:16 AM]