I am currently making a change password area and I wish for users to be able to change it although for passwords to be more secure we ask that passwords contain both letters and numbers and if users so choose they may have special characters as well..

I could not find anything PHP based that would help me check the password they are trying to change it to actually contains both numbers and letters, and if it contains characters that it accepts these also, although it will not cause an error if they don't have special characters...

So I want to be able to check for numbers and letters without removing special characters if they have them. If they don't have special characters that is fine.. although if they do not have a number or letter in their new password it will error..

Any help would be much appreciated!

6 Years
Discussion Span
Last Post by MagicMedia
if (empty($password)) {
	echo "Password is empty";
} else if (!preg_match("#[a-z]#i",$password)) {
	echo "Password needs letters";
} else if (!preg_match("#[0-9]#i",$password)) {
	echo "Password needs numbers";
} else {
	echo "Password has both letters and numbers";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.