vb.net regex question

  • Thread starter Thread starter engwar1
  • Start date Start date
E

engwar1

Not sure where to ask this. Please suggest another newsgroup if this
isn't the best place for this question.

I'm new to both vb.net and regex. I need a regular expression that will
validate what people are entering as their new password.

Must be between 6 and 10 characters
Must be alphanumeric only
Can not be the word "password" in any case ie "pAsSworD" should also be
denied.

the following works just fine for catching the lenght and the
alphanumeric requirement. My question really is how to match only if
"password" isn't their password.

"^([a-zA-Z0-9]{6,10})$"

Seems like it'd be easy but, like I said I'm new to regex.

Thanks!
 
I need a regular expression that will
validate what people are entering as their new password.

Must be between 6 and 10 characters
Must be alphanumeric only
Can not be the word "password" in any case ie "pAsSworD" should also be
denied.

Try

^((?<password>password)|[a-z0-9]{6,10})$

with the IgnoreCase and ExplicitCapture options.

If the "password" group (group 1) matches successfully, then the user
entered password. Otherwise, a successful match is a valid password.
 
Jon's suggestion will work if you have access to the match group in code. If
you are using this with a validation control, you normally would not have
access to this and could use something like this instead:

^(?!password$)[a-z0-9]{6,9}$

This uses "negative lookahead" to reject any string that is just the word
"password". As in Jon's example, use IgnoreCase. I assume from the original
message that "passwordX" would be a legitimate password and have allowed
this case, if not, it is easy to modify the regex to reject it.

I tested this in Expresso, but recommend the newest version, available at:

http://ultrapico.com


Jon Shemitz said:
I need a regular expression that will
validate what people are entering as their new password.

Must be between 6 and 10 characters
Must be alphanumeric only
Can not be the word "password" in any case ie "pAsSworD" should also be
denied.

Try

^((?<password>password)|[a-z0-9]{6,10})$

with the IgnoreCase and ExplicitCapture options.

If the "password" group (group 1) matches successfully, then the user
entered password. Otherwise, a successful match is a valid password.
 
Oops! I meant to allow 10 alphanumerics, not 9. Here is the corrected regex:

^(?!password$)[a-z0-9]{6,10}$


Jon Shemitz said:
I need a regular expression that will
validate what people are entering as their new password.

Must be between 6 and 10 characters
Must be alphanumeric only
Can not be the word "password" in any case ie "pAsSworD" should also be
denied.

Try

^((?<password>password)|[a-z0-9]{6,10})$

with the IgnoreCase and ExplicitCapture options.

If the "password" group (group 1) matches successfully, then the user
entered password. Otherwise, a successful match is a valid password.
 
Back
Top