I have a password validation script in PHP that checks a few different regular expressions, and throws a unique error message depending on which one fails. Here is an array of the regular expressions and the error messages that are thrown if the match fails:
array(
'rule1' => array(
'/^.*[\d].*$/i',
'Password must contain at least one number.'
),
'rule2' => array(
'/^.*[a-z].*$/i',
'Password must contain at least one lowercase letter'
),
'rule3' => array(
'/^.*[A-Z].*$/i',
'Password must contain at least one uppercase letter'
),
'rule4' => array(
'/^.*[~!@#$%^&*()_+=].*$/i',
'Password must contain at least one special character [~!@#$%^&*()_+=]'
)
);
For some reason, no matter what I pass through the validation, the "Special Characters" rule fails. I'm guessing it's a problem with the expression. If there's a better (or correct) way to write these expressions, I'm all ears!