P: n/a

I am trying to work out a regular expression which will validate a
password box.
The following rules apply
Must be 8 characters
Must have at least one digit (09) and at least one character (az or
AZ)
No special characters allowed except for full stop.
I am struggling to get to grips with regular expressions. Can anyone
help me with this please.
Thanks in anticipation
Ros Lee  
Share this Question
P: n/a

Maybe we need to && the conditional statements with three regex patterns:
r1 = [azAZ09]{8}
r2 = [azAZ]{1,7}
r3 = [09]{1,7}
or just use r2 "anded" to r3 with a string length of 8.
Eg.:
option 1: (I like this one better. It has a more definitive and tighter
constraint on the string pattern compared to opt2)
if ((Regex.IsMatch(sPassword, r1)) &&
(Regex.IsMatch(sPassword, r2)) &&
(Regex.IsMatch(sPassword, r3)))
option 2:
if ((Regex.IsMatch(sPassword, r2)) &&
(Regex.IsMatch(sPassword, r3)) &&
(sPassword.Length == 8)) http://www.regularexpressions.info/ has a good tutorial on regex.
Try it see if either works and good luck,
/Js.
"Roz Lee" <ro**@panztel.com> wrote in message
news:b7************************@posting.google.com ... I am trying to work out a regular expression which will validate a password box.
The following rules apply Must be 8 characters Must have at least one digit (09) and at least one character (az or AZ) No special characters allowed except for full stop.
I am struggling to get to grips with regular expressions. Can anyone help me with this please. Thanks in anticipation
Ros Lee  
P: n/a

Maybe we need to && the conditional statements with three regex patterns:
r1 = [azAZ09]{8}
r2 = [azAZ]{1,7}
r3 = [09]{1,7}
or just use r2 "anded" to r3 with a string length of 8.
Eg.:
option 1: (I like this one better. It has a more definitive and tighter
constraint on the string pattern compared to opt2)
if ((Regex.IsMatch(sPassword, r1)) &&
(Regex.IsMatch(sPassword, r2)) &&
(Regex.IsMatch(sPassword, r3)))
option 2:
if ((Regex.IsMatch(sPassword, r2)) &&
(Regex.IsMatch(sPassword, r3)) &&
(sPassword.Length == 8)) http://www.regularexpressions.info/ has a good tutorial on regex.
Try it see if either works and good luck,
/Js.
"Roz Lee" <ro**@panztel.com> wrote in message
news:b7************************@posting.google.com ... I am trying to work out a regular expression which will validate a password box.
The following rules apply Must be 8 characters Must have at least one digit (09) and at least one character (az or AZ) No special characters allowed except for full stop.
I am struggling to get to grips with regular expressions. Can anyone help me with this please. Thanks in anticipation
Ros Lee  
P: n/a

Just out of curiousity  why use regular expressions? Your problem is
just a few lines of nonregular expression code  why not just code
it the boring old way?  
P: n/a

Just out of curiousity  why use regular expressions? Your problem is
just a few lines of nonregular expression code  why not just code
it the boring old way?  
P: n/a

Hi Jimi, Just out of curiousity  why use regular expressions? Your problem is just a few lines of nonregular expression code  why not just code it the boring old way?
I am almost writting that forever however in this case, I think it will
needs more lines.
What did you think of?
Cor  
P: n/a

Hi Jimi, Just out of curiousity  why use regular expressions? Your problem is just a few lines of nonregular expression code  why not just code it the boring old way?
I am almost writting that forever however in this case, I think it will
needs more lines.
What did you think of?
Cor  
P: n/a

I think you can use a positive lookahead to put the "and" into the regex:
"^(?=.*\d)(?=.*[azAZ])(?:.{8,})$"
I tested it only on a few cases, but it seems to work.
(I assume for password verification efficiency isn't that important)
Niki
"John Smith" <.@.> wrote in news:De*****************@twister.socal.rr.com... Maybe we need to && the conditional statements with three regex patterns: r1 = [azAZ09]{8} r2 = [azAZ]{1,7} r3 = [09]{1,7}
or just use r2 "anded" to r3 with a string length of 8.
Eg.: option 1: (I like this one better. It has a more definitive and tighter constraint on the string pattern compared to opt2) if ((Regex.IsMatch(sPassword, r1)) && (Regex.IsMatch(sPassword, r2)) && (Regex.IsMatch(sPassword, r3)))
option 2: if ((Regex.IsMatch(sPassword, r2)) && (Regex.IsMatch(sPassword, r3)) && (sPassword.Length == 8)) http://www.regularexpressions.info/ has a good tutorial on regex.
Try it see if either works and good luck, /Js.
"Roz Lee" <ro**@panztel.com> wrote in message news:b7************************@posting.google.com ... I am trying to work out a regular expression which will validate a password box.
The following rules apply Must be 8 characters Must have at least one digit (09) and at least one character (az or AZ) No special characters allowed except for full stop.
I am struggling to get to grips with regular expressions. Can anyone help me with this please. Thanks in anticipation
Ros Lee
 
P: n/a

I think you can use a positive lookahead to put the "and" into the regex:
"^(?=.*\d)(?=.*[azAZ])(?:.{8,})$"
I tested it only on a few cases, but it seems to work.
(I assume for password verification efficiency isn't that important)
Niki
"John Smith" <.@.> wrote in news:De*****************@twister.socal.rr.com... Maybe we need to && the conditional statements with three regex patterns: r1 = [azAZ09]{8} r2 = [azAZ]{1,7} r3 = [09]{1,7}
or just use r2 "anded" to r3 with a string length of 8.
Eg.: option 1: (I like this one better. It has a more definitive and tighter constraint on the string pattern compared to opt2) if ((Regex.IsMatch(sPassword, r1)) && (Regex.IsMatch(sPassword, r2)) && (Regex.IsMatch(sPassword, r3)))
option 2: if ((Regex.IsMatch(sPassword, r2)) && (Regex.IsMatch(sPassword, r3)) && (sPassword.Length == 8)) http://www.regularexpressions.info/ has a good tutorial on regex.
Try it see if either works and good luck, /Js.
"Roz Lee" <ro**@panztel.com> wrote in message news:b7************************@posting.google.com ... I am trying to work out a regular expression which will validate a password box.
The following rules apply Must be 8 characters Must have at least one digit (09) and at least one character (az or AZ) No special characters allowed except for full stop.
I am struggling to get to grips with regular expressions. Can anyone help me with this please. Thanks in anticipation
Ros Lee
 
P: n/a

> Cor Ligthertwrote:
I am almost writting that forever however in this case, I think it
will needs more lines. What did you think of? Cor
Suppose the regular expression approach takes 4 lines and 1 hour. My
approach to this trivial problem takes 12 lines and 5 minutes. This
is an easy business decision  there is no need to minimize the
number of lines of code if the tradeoff is this drastic.
I can see using regular expressions for complex problems, but it's
massive overkill for small problems.  
P: n/a

> Cor Ligthertwrote:
I am almost writting that forever however in this case, I think it
will needs more lines. What did you think of? Cor
Suppose the regular expression approach takes 4 lines and 1 hour. My
approach to this trivial problem takes 12 lines and 5 minutes. This
is an easy business decision  there is no need to minimize the
number of lines of code if the tradeoff is this drastic.
I can see using regular expressions for complex problems, but it's
massive overkill for small problems.  
P: n/a

Hi Jimi,
We agree your text completly, and now looking the question over again, I
think we agree completly about this subject.
Probably is meant 2 X the 26 basic characters plus 10 numeric characters
plus an limited set of special characters, while I was thinking about all
full possible unicode set for that.
I think now also that it is simple possible without the Regex and that is
the one I always avoid. To add something to your text:
"And it needs 24 hours when updating the program, to find out what was meant
with it"
:)
Cor  
P: n/a

Hi Jimi,
We agree your text completly, and now looking the question over again, I
think we agree completly about this subject.
Probably is meant 2 X the 26 basic characters plus 10 numeric characters
plus an limited set of special characters, while I was thinking about all
full possible unicode set for that.
I think now also that it is simple possible without the Regex and that is
the one I always avoid. To add something to your text:
"And it needs 24 hours when updating the program, to find out what was meant
with it"
:)
Cor  
P: n/a

Hi Jimi,
I definitely agree with your line of reasoning. But in this regard, I'm not
sure if the 1h to 5 mins ratio apply. We are, after all, talking about
validating only a few characters, and not a full text file. So short and
expressiveness wherever applicable is also a good choice.
Niki also gave a more concise pattern. So :) in the end it depends to the
programmer to choose which method she wants to use. We're merely responding
to her question with an expected type of answer, rather than ask why not
this or that.
/Js.
"Jimi" <ji************@yahoodotca.nospam.invalid> wrote in message
news:40**********@127.0.0.1... Cor Ligthertwrote: I am almost writting that forever however in this case, I think it will needs more lines. What did you think of? Cor
Suppose the regular expression approach takes 4 lines and 1 hour. My approach to this trivial problem takes 12 lines and 5 minutes. This is an easy business decision  there is no need to minimize the number of lines of code if the tradeoff is this drastic.
I can see using regular expressions for complex problems, but it's massive overkill for small problems.  
P: n/a

"Jimi" <ji************@yahoodotca.nospam.invalid> wrote in
news:40**********@127.0.0.1... ... Suppose the regular expression approach takes 4 lines and 1 hour.
I didn't spend more than 5 minutes on that regex (including testing).
Maybe your regex skills need some training ;)
My approach to this trivial problem takes 12 lines and 5 minutes.
Including testing? (bufferoverruns, chinese unicode characters...)
(The .net regexengine already is welltested)
This is an easy business decision  there is no need to minimize the number of lines of code if the tradeoff is this drastic.
You don't know the OP's code.
Maybe the passwordcheckrules should be stored in a configuration file?
Or maybe an admin should be able to modify them?
Maybe the OP uses a validation framework that will only accept regular
expressions?
Or maybe she simple wants to get a better understanding of regular
expressions.
I can see using regular expressions for complex problems, but it's massive overkill for small problems.
Definitely, but it's hard to tell if this is one of the complex problems or
only a simple one. (see above)
Niki   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 2700
 replies: 14
 date asked: Nov 22 '05
