$pw = $_POST["password"];
if(empty($_POST))
{ echo "
No password input";}
else { echo "Your password is: ".$pw.""; }
$result;
if ( preg_match("/([0-9a-z]{1})(\s)([0-9a-z]{1})/", $pw) ||
preg_match("/^(\s)/", $pw) ||
preg_match("/(\s)$/", $pw)
) {
$result = "
your password contains spaces, no spaces allowed";
}
if (preg_match("/^([a-z]{1,5})$/", $pw)) {
$result .= "
you password has less then 6 letters.";
}
if (!preg_match("/(\d{1})/", $pw)) {
$result .= "
you need at least 1 number.";
}
if (preg_match("/[A-Z]{1}/", $pw)) {
$result .= "
No capital letters";
}
if (preg_match("/.*^(?=.{6})(?!.*[A-Z]{1})(?=.*[a-z])(?=.*[0-9]).*$/", $pw)) {
$result .= "
Your password is good";
}
if (empty($pw)){$result = "";}
echo $result;
password invalid
password is good
I break down the regular expression used in this example in my blog
var patt1=new RegExp(".*^(?=.{6})(?=.*[a-z])(?=.*[0-9]).*$");
$('#jq-pw').keyup(function() {
var inputpw = $('#jq-pw').val();
$(".bad, .good").removeClass("show");
$(".bad").addClass("show");
if(patt1.test(inputpw)){
$(".bad").removeClass("show");
$(".good").addClass("show");
};
});
You can also fork my jQuery/JS version on jsFiddle.net