|
-
Mar 26th, 2003, 08:23 PM
#1
Thread Starter
Addicted Member
(Resolved) User Login Issues
I need the user to input an Alias. The alias must have no spaces, using only leters or numbers(no #,†,Æ,^ and so on...) how would I do this using VB?
Last edited by Illiad; Mar 26th, 2003 at 08:53 PM.
Quis Custodiet Ipsos Custodes?
You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.
-
Mar 26th, 2003, 08:39 PM
#2
Using the Validate Event will cover you from the user 'Pasting' data in aswell.
Like:
VB Code:
Option Explicit
Const sCompare As String = "abcdefghijklmnopqrstuvwxyz0123456789"
Private Sub Text1_Validate()
Dim indx As Long
For indx = 1 To Len(Text1.Text)
If InStr(1, sCompare, Mid$(Text1.Text, indx, 1), vbTextCompare) = 0 Then
MsgBox "This isn't alowed : " & """" & Mid$(Text1.Text, indx, 1) & """"
Exit For
End If
Next
End Sub
-
Mar 26th, 2003, 08:42 PM
#3
Also,
Highlighting the offending char:
VB Code:
For indx = 1 To Len(Text1.Text)
If InStr(1, sCompare, Mid$(Text1.Text, indx, 1), vbTextCompare) = 0 Then
MsgBox "This isn't alowed : " & """" & Mid$(Text1.Text, indx, 1) & """"
[b]Text1.SelStart = indx - 1
Text1.SelLength = 1
Text1.SetFocus[/b]
Exit For
End If
Next
-
Mar 26th, 2003, 08:45 PM
#4
Frenzied Member
One thing Bruce missed there was the Cancel paramter to the Validate event. If the data doesn't pass validation, then you should set the Cancel parameter to True. Also, you wont need the SetFocus method since focus won't leave the textbox:
VB Code:
Private Sub Text1_Validate([b]Cancel As Boolean[/b])
Dim indx As Long
For indx = 1 To Len(Text1.Text)
If InStr(1, sCompare, Mid$(Text1.Text, indx, 1), vbTextCompare) = 0 Then
MsgBox "This isn't alowed : " & """" & Mid$(Text1.Text, indx, 1) & """"
Text1.SelStart = indx - 1
Text1.SelLength = 1
[b]Cancel = True[/b]
Exit For
End If
Next
End Sub
This will prevent them from leaving the Textbox until they fix the error.
-
Mar 26th, 2003, 08:56 PM
#5
Unfortunatly, I was testing it in VBA.
TextBox's dont have a Validate Event, so I had to rely on memory. And I tested with a CommandButton in lieu of
the Validate Event, hence the need for SetFocus.... 
Cheers,
Bruce.
-
Mar 26th, 2003, 08:58 PM
#6
Frenzied Member
Impressive memory!
-
Mar 26th, 2003, 09:02 PM
#7
Thread Starter
Addicted Member
I got it dont worry!
inside the if statment I made a Goto bottom and i just sends it to the "End Sub" and instead of hilighting it i just cleared the text box...
Quis Custodiet Ipsos Custodes?
You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.
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
|