-
Dec 2nd, 2006, 03:37 PM
#1
Thread Starter
New Member
[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
-
Dec 2nd, 2006, 04:16 PM
#2
Thread Starter
New Member
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
-
Dec 2nd, 2006, 04:24 PM
#3
Lively Member
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:
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim pw As String' the password you want to check
Dim p As Integer
Dim digit As Boolean' true if a digit is found in the password
Dim cap As Boolean' true if a uppercase letter is found in the password
Dim low As Boolean' true if a lowercase letter is found in the password
pw = tb1.Text' stores tb1 in the string "pw"
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
If Char.IsDigit(pw, p) Then
digit = True
End If
If Char.IsUpper(pw, p) Then
cap = True
End If
If Char.IsLower(pw, p) Then
low = True
End If
Next p
If digit = True And cap = True And low = True Then' if all 3 requirments are met then
lbl1.Text = "Password is good!"
Else : lbl1.Text = "Bad password make sure you used at least 1 digit 1 lowercase letter and 1 uppercase letter in the password"
End If
End Sub
-
Dec 2nd, 2006, 09:37 PM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|