469,955 Members | 2,196 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Checking password input with regular expression

JJ
To validate a password as the user is registering I want to use a regular
expressio validator.

I got this one from the Microsoft web site for validating a password of at
least 7 characters, with at least one number and one non-alphanumeric
character:

@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})

Yet I can't get it to validate that a password like qwertyui123# fits the
criteria.

Or any password for that matter. Can anyone help with a regular expression
that works? or am I goong wrong somewhere?

JJ
Sep 18 '06 #1
7 2574
I got this one from the Microsoft web site for validating a password of at
least 7 characters, with at least one number and one non-alphanumeric
character:

@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})

Yet I can't get it to validate that a password like qwertyui123# fits the
criteria.
@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

This one works, just a typing mistake.

Markus

Sep 18 '06 #2
it does not work for me... is there something I should know? I tested it
on this site : http://regexlib.com/RETester.aspx?regexp_id=887 and it never
matches.

thanks

ThunderMusic

"Markus Palme" <Ma*********@googlemail.coma écrit dans le message de news:
11**********************@i3g2000cwc.googlegroups.c om...
>I got this one from the Microsoft web site for validating a password of
at
least 7 characters, with at least one number and one non-alphanumeric
character:

@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})

Yet I can't get it to validate that a password like qwertyui123# fits
the
criteria.

@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

This one works, just a typing mistake.

Markus

Sep 19 '06 #3
JJ
Markus,

Surely by changing the 'W' to 'w' you are not looking for patterns with
non-alphanumeric characters in it?

the (?=*\W){1}) means the pattern must have one or more non-alphanumeric
characters in it.

I think the problem lies with the initial @\" . Clearly the expression is
trying to match a pattern that does not have a '@' or a ' " ' in it, but if
you remove this part of the expression, it works as expected, allbeit
allowing those 2 'disallowed' characters.

Anyone work out what the correct notation should be?

JJ

"Markus Palme" <Ma*********@googlemail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>I got this one from the Microsoft web site for validating a password of
at
least 7 characters, with at least one number and one non-alphanumeric
character:

@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})

Yet I can't get it to validate that a password like qwertyui123# fits
the
criteria.

@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

This one works, just a typing mistake.

Markus

Sep 19 '06 #4

JJ schrieb:
Markus,

Surely by changing the 'W' to 'w' you are not looking for patterns with
non-alphanumeric characters in it?
My mistake, sorry - I missed the "non-"alphanumeric. The regex of
course, is only this part:

(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

Markus

Sep 19 '06 #5
JJ
Sorry Markus I still can't see that it makes sense to me.

If I am searching for a pattern that matches 7 or more characters containing
1 or more digits and 1 or more non-alphanumeric characters,
I can't see how this would work.

I understand I may be going wrong somewhere, but where?

The original @\" at the beginning was meant to make sure that those
characters are not part of the password. So, as far as I can see they do
need to be part of the regular expression.

JJ

"Markus Palme" <Ma*********@googlemail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>
JJ schrieb:
>Markus,

Surely by changing the 'W' to 'w' you are not looking for patterns with
non-alphanumeric characters in it?

My mistake, sorry - I missed the "non-"alphanumeric. The regex of
course, is only this part:

(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

Markus

Sep 19 '06 #6
JJ
How about this one:

^.*(?=.{7,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[@#$%^&+=]).*$

That breaks down as:

7 characters;
must contain a digit;
must contain a character in the range a-z or A-Z;
must contain one of these characters @#$%^&+=

I've run some quick tests and its seems to work for me, but be grateful for
anyone elses views?

JJ


"JJ" <ab*@xyz.comwrote in message
news:ua****************@TK2MSFTNGP05.phx.gbl...
Sorry Markus I still can't see that it makes sense to me.

If I am searching for a pattern that matches 7 or more characters
containing 1 or more digits and 1 or more non-alphanumeric characters,
I can't see how this would work.

I understand I may be going wrong somewhere, but where?

The original @\" at the beginning was meant to make sure that those
characters are not part of the password. So, as far as I can see they do
need to be part of the regular expression.

JJ

"Markus Palme" <Ma*********@googlemail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>>
JJ schrieb:
>>Markus,

Surely by changing the 'W' to 'w' you are not looking for patterns with
non-alphanumeric characters in it?

My mistake, sorry - I missed the "non-"alphanumeric. The regex of
course, is only this part:

(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

Markus


Sep 19 '06 #7
ok, so Here it is, the supreme regex for passwords... ;)

^.*(?=.{7,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-z])(?=.*[^a-zA-Z0-9])|(?=.*\d)(?=.*[A-Z])(?=.*[^a-zA-Z0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])).*$

it tests for 3 of these 4 cases : 1 a-z, 1 A-Z, 1 digit, 1 non-alphanumeric.
7 chars minimum... you can test it, it works fine... I'll add it to my
validations.

I hope helps

ThunderMusic
"JJ" <ab*@xyz.comwrote in message
news:ON**************@TK2MSFTNGP06.phx.gbl...
How about this one:

^.*(?=.{7,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[@#$%^&+=]).*$

That breaks down as:

7 characters;
must contain a digit;
must contain a character in the range a-z or A-Z;
must contain one of these characters @#$%^&+=

I've run some quick tests and its seems to work for me, but be grateful
for anyone elses views?

JJ


"JJ" <ab*@xyz.comwrote in message
news:ua****************@TK2MSFTNGP05.phx.gbl...
>Sorry Markus I still can't see that it makes sense to me.

If I am searching for a pattern that matches 7 or more characters
containing 1 or more digits and 1 or more non-alphanumeric characters,
I can't see how this would work.

I understand I may be going wrong somewhere, but where?

The original @\" at the beginning was meant to make sure that those
characters are not part of the password. So, as far as I can see they do
need to be part of the regular expression.

JJ

"Markus Palme" <Ma*********@googlemail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
>>>
JJ schrieb:

Markus,

Surely by changing the 'W' to 'w' you are not looking for patterns with
non-alphanumeric characters in it?

My mistake, sorry - I missed the "non-"alphanumeric. The regex of
course, is only this part:

(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

Markus



Sep 19 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Antoni | last post: by
13 posts views Thread by Eddie | last post: by
2 posts views Thread by SL | last post: by
reply views Thread by =?Utf-8?B?am1obWFpbmU=?= | last post: by
4 posts views Thread by Jon Paal | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.