By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Regular expression

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"vvenk" wrote:
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.

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.