Results 1 to 7 of 7

Thread: (Resolved) User Login Issues

  1. #1

    Thread Starter
    Addicted Member Illiad's Avatar
    Join Date
    Mar 2003
    Location
    Chicago
    Posts
    196

    (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.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Using the Validate Event will cover you from the user 'Pasting' data in aswell.

    Like:
    VB Code:
    1. Option Explicit
    2.  
    3. Const sCompare As String = "abcdefghijklmnopqrstuvwxyz0123456789"
    4.  
    5. Private Sub Text1_Validate()
    6.  
    7.     Dim indx As Long
    8.  
    9.     For indx = 1 To Len(Text1.Text)
    10.         If InStr(1, sCompare, Mid$(Text1.Text, indx, 1), vbTextCompare) = 0 Then
    11.             MsgBox "This isn't alowed : " & """" & Mid$(Text1.Text, indx, 1) & """"
    12.             Exit For
    13.         End If
    14.     Next
    15.  
    16. End Sub

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Also,

    Highlighting the offending char:
    VB Code:
    1. For indx = 1 To Len(Text1.Text)
    2.         If InStr(1, sCompare, Mid$(Text1.Text, indx, 1), vbTextCompare) = 0 Then
    3.             MsgBox "This isn't alowed : " & """" & Mid$(Text1.Text, indx, 1) & """"
    4.             [b]Text1.SelStart = indx - 1
    5.             Text1.SelLength = 1
    6.             Text1.SetFocus[/b]
    7.             Exit For
    8.         End If
    9.     Next

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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:
    1. Private Sub Text1_Validate([b]Cancel As Boolean[/b])
    2.     Dim indx As Long
    3.  
    4.     For indx = 1 To Len(Text1.Text)
    5.         If InStr(1, sCompare, Mid$(Text1.Text, indx, 1), vbTextCompare) = 0 Then
    6.             MsgBox "This isn't alowed : " & """" & Mid$(Text1.Text, indx, 1) & """"
    7.             Text1.SelStart = indx - 1
    8.             Text1.SelLength = 1
    9.             [b]Cancel = True[/b]
    10.             Exit For
    11.         End If
    12.     Next
    13. End Sub
    This will prevent them from leaving the Textbox until they fix the error.
    ~seaweed

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Impressive memory!
    ~seaweed

  7. #7

    Thread Starter
    Addicted Member Illiad's Avatar
    Join Date
    Mar 2003
    Location
    Chicago
    Posts
    196
    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
  •  



Click Here to Expand Forum to Full Width