I have written a regular expression which could potentially be used for password strength validation:
^(?:([A-Z])*([a-z])*(\\d)*(\\W)*){8,12}$
Here was my final solution based on sp00m's answer:
function testPassword(pwString) {
var strength = 0;
strength += /[A-Z]+/.test(pwString) ? 1 : 0;
strength += /[a-z]+/.test(pwString) ? 1 : 0;
strength += /[0-9]+/.test(pwString) ? 1 : 0;
strength += /[\W]+/.test(pwString) ? 1 : 0;
switch(strength) {
case 3:
// its's medium!
break;
case 4:
// it's strong!
break;
default:
// it's weak!
break;
}
}
I've added this purely for reference, however have accepted sp00m's answer since it was their answer that let me to this solution.