P: n/a

Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user
enters conforms to the following rules:
1. It has to be between 320 characters long.
2. Only az, AZ, 09, +_ are allowed.
3. At least one occurence of a lower case letter, a upper case letter and a
digit has to be used.
Any help will be appreciated.  
Share this Question
P: n/a

Hi wenk,
try the next regular expression:
^([azAZ09\+\\(_)]{3,20})$
(test it first please)
I hope that helps.
Kind Regards,
Jorge Serrano
MVP VB.NET
"vvenk" wrote: Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user enters conforms to the following rules:
1. It has to be between 320 characters long. 2. Only az, AZ, 09, +_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a digit has to be used.
Any help will be appreciated.  
P: n/a

Hi vvenk
Jorge's RegEx is a good start  it satisfies rules 1 and 2  but it would
allow 'aaa' as a valid input for example.
You could use this regular expression followed by a second test against
[09], a third test against [AZ], and a fourth against [az], to satisfy
rule number 3.
Nigel
"Jorge Serrano [MVP VB]" wrote: Hi wenk,
try the next regular expression: ^([azAZ09\+\\(_)]{3,20})$
(test it first please)
I hope that helps.
Kind Regards,
Jorge Serrano MVP VB.NET
"vvenk" wrote:
Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user enters conforms to the following rules:
1. It has to be between 320 characters long. 2. Only az, AZ, 09, +_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a digit has to be used.
Any help will be appreciated.  
P: n/a

Nigel:
Thank you.
Here's my subroutine that tests the password using the regular expression
that Jorge had suggested:
Private sub test_password
Dim lsPassword As String
Dim lsPattern As String = "^([azAZ09\+\\(_)]{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
However, when I test it, mc.count is 1 when I expect it to be 0. So, it
breaks Rule 1. The only rule this enforces is Rule 2.
Of cource, your suggestion addresses enforcing Rule 3.
Thanks.
"Nigel Armstrong" wrote: Hi vvenk
Jorge's RegEx is a good start  it satisfies rules 1 and 2  but it would allow 'aaa' as a valid input for example.
You could use this regular expression followed by a second test against [09], a third test against [AZ], and a fourth against [az], to satisfy rule number 3.
Nigel
"Jorge Serrano [MVP VB]" wrote:
Hi wenk,
try the next regular expression: ^([azAZ09\+\\(_)]{3,20})$
(test it first please)
I hope that helps.
Kind Regards,
Jorge Serrano MVP VB.NET
"vvenk" wrote:
Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user enters conforms to the following rules:
1. It has to be between 320 characters long. 2. Only az, AZ, 09, +_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a digit has to be used.
Any help will be appreciated.  
P: n/a

Jorge:
Thanks for your help. Can you clarify the following questions?
1. I understand the use of ""; it's an "or". I see that you are saying
"(any alpha or number)" or "+" or "". I don't understand "\(_)". Why can't I
say \_. What is the significance of the open and close paranthesis?
2. Also, this does not seem to enforce Rule 1 concering the minimum and the
maximum length.
Thanks.
Venkat
"Jorge Serrano [MVP VB]" wrote: Hi wenk,
try the next regular expression: ^([azAZ09\+\\(_)]{3,20})$
(test it first please)
I hope that helps.
Kind Regards,
Jorge Serrano MVP VB.NET
"vvenk" wrote:
Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user enters conforms to the following rules:
1. It has to be between 320 characters long. 2. Only az, AZ, 09, +_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a digit has to be used.
Any help will be appreciated.  
P: n/a

Jorge:
Sorry, my apologies. I was used the same variable for both the pattern and
the string.
Thanks to you and Nigel, I am a happy camper.
Venkat
"Jorge Serrano [MVP VB]" wrote: Hi wenk,
try the next regular expression: ^([azAZ09\+\\(_)]{3,20})$
(test it first please)
I hope that helps.
Kind Regards,
Jorge Serrano MVP VB.NET
"vvenk" wrote:
Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user enters conforms to the following rules:
1. It has to be between 320 characters long. 2. Only az, AZ, 09, +_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a digit has to be used.
Any help will be appreciated.  
P: n/a

Jorge:
Sorry, my apologies. I was used the same variable for both the pattern and
the string.
Thanks to you and Nigel, I am a happy camper.
Venkat
"Jorge Serrano [MVP VB]" wrote: Hi wenk,
try the next regular expression: ^([azAZ09\+\\(_)]{3,20})$
(test it first please)
I hope that helps.
Kind Regards,
Jorge Serrano MVP VB.NET
"vvenk" wrote:
Hello:
I am trying to learn about regular expressions.
How would I use regular expressions to ensure that the password an user enters conforms to the following rules:
1. It has to be between 320 characters long. 2. Only az, AZ, 09, +_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a digit has to be used.
Any help will be appreciated.   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 1048
 replies: 6
 date asked: Nov 21 '05
