Regular expression

G

Guest

Hello:

I am trying to use regular expressions to enforce the following requirements
on a password:

1. It has to be between 3-20 characters long.
2. Only a-z, A-Z, 0-9, +-_ are allowed.
3. At least one occurence of a lower case letter, a upper case letter and a
digit has to be used.

Two gentlemen guided me on this and based on their suggestion, I have the
following sub-routine:

Private sub test_password
Dim lsPassword As String
Dim lsPattern As String = "^([a-zA-Z0-9|\+|\-\(_)]{3,20})$"
lsPassword = "aa"
Dim mc As MatchCollection = Regex.Matches(lsPassword, lsPassword)
Dim m As Match

For Each m In mc
MsgBox(m.ToString)
Next
End Sub

I understand that mc collect how many matches it finds. So, in the above
example, I expect to get an array of 2.

But I see that Rules 1 and 3 are not enforced.

Can somebody suggest alternate ideas?

Thanks.
 
G

Guest

Sorry, my mistake. I see that my pattern and the string are one and the same
and that's why it did not work.

Venkat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top