Thanks for helping me out crabboy, this regular expression stuff is making me pull out my hair. A couple of questions:
1. Doesn't the code below state that as long as it is between 8-15 characters, contains the letters a-z (or A-Z), contains the numbers 1-9, and contains anything other than the two above, it will pass. I was told that ^ means not and the third criteria seems to say anything else matches.
if ( strlen( $newpass ) > 8 && strlen($newpass) < 15 )
if ( preg_match('([a-zA-Z])',$newpass))
if ( preg_match('([0-9])',$newpass))
if ( preg_match('([^a-zA-Z0-9])',$newpass))
$good = true;
My boss is trying to make me learn regexp in PHP and would like to see me make it one preg_match. I have gotten pretty close to solving it, but the code below still rejects "aaa123!@&" as containing illegal characters.
Here is where I am so far..
<?php
$newpass = $_POST['newpass'];
if(preg_match("/^([a-zA-Z])|^([0-9])|^([\!\@\*\%\^\&])/", $newpass)) {
echo "Password contains illegal characters!";
} else {
echo "Password passes preg_match test!!";
};
?>
I know I am close here but just can't seem to make it work as I read it.
