I have written a regular expression which could potentially be used for password strength validation:
^(?:([A-Z])*([a-z])*(\\d)*(\\W)*){8,12}$
You can do it by separating each group out and match them one by one, like this:
var level = 0;
var input = '';//user input goes here
switch(true){
case /^(?:([A-Z])*){8,12}$/.test(input):
level = 1;
break;
case /^(?:([A-Z])*([a-z])*){8,12}$/.test(input):
level = 2;
break;
case /^(?:([A-Z])*([a-z])*(\d)*){8,12}$/.test(input):
level = 3;
break;
case /^(?:([A-Z])*([a-z])*(\d)*(\W)*){8,12}$/.test(input):
level = 4;
break;
}
The level
variable goes from 1 (the weakest) to 4 (the strongest).