Forum Moderators: coopster

Message Too Old, No Replies

a difficult regex pattern

ask the PHP forum cuz ure smart

         

httpwebwitch

2:03 pm on Oct 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need a regular expression that matches this criteria, for validating a user-suggested password: "must contain an upper case letter, a lower case letter, a numeric digit and a punctuation, in any order"

is it possible to do that all in one pattern?

PHP_Chimp

4:58 pm on Oct 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This isnt mine (cant remember where I got it) -

^(([A-Za-z]+[^0-9]*)([0-9]+[^\W]*)([\W]+[\W0-9A-Za-z]*))¦
(([A-Za-z]+[^\W]*)([\W]+[^0-9]*)([0-9]+[\W0-9A-Za-z]*))¦
(([\W]+[^A-Za-z]*)([A-Za-z]+[^0-9]*)([0-9]+[\W0-9A-Za-z]*))¦
(([\W]+[^0-9]*)([0-9]+[^A-Za-z]*)([A-Za-z]+[\W0-9A-Za-z]*))¦
(([0-9]+[^A-Za-z]*)([A-Za-z]+[^\W]*)([\W]+[\W0-9A-Za-z]*))¦
(([0-9]+[^\W]*)([\W]+[^A-Za-z]*)([A-Za-z]+[\W0-9A-Za-z]*))$

Iv broken it at the pipes but it should be all on one line.

eelixduppy

4:22 pm on Oct 6, 2007 (gmt 0)



You can do something like this, too:

function check_password($string) {
if(preg_match("/[a-z]/",$string) && preg_match("/[A-Z]/",$string) && preg_match("/[0-9]/",$string) && preg_match("/[,.?!;:]/",$string)) {
return 1;
} else {
return 0;
}
}

A little more function calls but easier to see.