|
-
Jul 4th, 2000, 09:46 PM
#1
Thread Starter
Addicted Member
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
-
Jul 4th, 2000, 09:59 PM
#2
Thread Starter
Addicted Member
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.
-
Jul 4th, 2000, 10:05 PM
#3
Thread Starter
Addicted Member
ok I see my dumb ass mistake now the length property int he mid$ should have been 1 instead of i.
-
Jul 5th, 2000, 01:09 AM
#4
Lively Member
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
Andrew Empson
vb6(ent) SP4
-
Jul 5th, 2000, 01:20 AM
#5
Thread Starter
Addicted Member
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
-
Jul 5th, 2000, 01:41 AM
#6
Member
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
Mikey
A/P
Using VB6 SP4 Enterprise Ed.
-
Jul 5th, 2000, 05:13 AM
#7
Hyperactive Member
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
|