Results 1 to 4 of 4

Thread: [2005] need help with Regular Expressions

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    10

    [2005] need help with Regular Expressions

    Hi all -
    I am trying to validate the creation of new passwords.
    I am trying to force users to use at least one digit, lower and uppper case letter.

    The code i am using is from a video showing a user using VS2003. However, I am using vs2005 - i'm not sure if this is affecting it.
    The code I am using returns an error no matter what I enter into the form (including values that should be OK).
    Can you spot any errrors in my regular expression string (or anywhere here, really )?

    Here is my code:
    Code:
        Private Sub TextBox1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
            If Regex.IsMatch(Me.PasswordTextBox.Text, "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,20}$") = True Then
                Me.ErrorProvider1.SetError(Me.TextBox1, Nothing)
                MsgBox("Match!!")
            Else
                Me.ErrorProvider1.SetError(Me.TextBox1, "Invalid Password")
                MsgBox("No Match!!")
            End If
        End Sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    10

    Re: [2005] need help with Regular Expressions

    update: apparently my code works, I redid the whole form and now it is working perfectly. Goodbye 3 hours of my life searching for a solution for nothing

  3. #3
    Lively Member
    Join Date
    Mar 2006
    Posts
    104

    Re: [2005] need help with Regular Expressions

    not sure if this is what you want but try this code you need a textbox(tb1) and a button(btn1)


    VB Code:
    1. Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
    2.         Dim pw As String' the password you want to check
    3.         Dim p As Integer
    4.         Dim digit As Boolean' true if a digit is found in the password
    5.         Dim cap As Boolean' true if a uppercase letter is found in the password
    6.         Dim low As Boolean' true if a lowercase letter is found in the password
    7.  
    8.         pw = tb1.Text' stores tb1 in the string "pw"
    9.  
    10.  
    11.  
    12.         For p = 0 To pw.Length - 1' loop through the string 1 character at a time and see if the character is a number, uppercase or lowercase
    13.  
    14.             If Char.IsDigit(pw, p) Then
    15.                 digit = True
    16.             End If
    17.  
    18.             If Char.IsUpper(pw, p) Then
    19.                 cap = True
    20.             End If
    21.  
    22.             If Char.IsLower(pw, p) Then
    23.                 low = True
    24.             End If
    25.  
    26.         Next p
    27.  
    28.         If digit = True And cap = True And low = True Then' if all 3 requirments are met then
    29.             lbl1.Text = "Password is good!"
    30.         Else : lbl1.Text = "Bad password make sure you used at least 1 digit 1 lowercase letter and 1 uppercase letter in the password"
    31.         End If
    32.  
    33.  
    34.     End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    10

    Re: [2005] need help with Regular Expressions

    cool, thanks for the code, much appreciated. I'll try it out also (I got my original code to work somehow )

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