java正则验证密码强度,密码强度验证的正则表达式
I have written a regular expression which could potentially be used for password strength validation:
^(?:([A-Z])*([a-z])*(\d)*(\W)*){8,12}$
The expression consists of four groups:
Zero or more uppercase characters
Zero or more lowercase characters
Zero or more decimal digits
Zero or more non-word characters (!, £, $, %, etc.)
The way I want it to work is to determine how many of the groups have been matched in order to determine the strength of the password. so for example, if only 1 group is matched, it would be weak. If all four groups were matched, it would be strong.
Here I can see visually, how many groups are matched, but I want to do this in JavaScript. I wrote a scr
ipt that returns the number of matched groups, but the results were not the same as I can see in Rubular.
How can I achieve this in JavaScript? and is my regular expression up to the task?
解决⽅案
I think you'll have to check each group independently. Pseudo-code:
bool[] array = {};
array[0] = pwd.match(/[A-Z]/);
array[1] = pwd.match(/[a-z]/);
array[2] = pwd.match(/\d/);
array[3] = pwd.match(/[!_.-]/);
int sum = 0;
for (int i=0; i
sum += array[i] ? 1 : 0;
}
switch (sum) {
case 0: print(""); break;
case 1: print("weak"); break;
case 2: print("ok"); break;
时间正则表达式javacase 3: print("strong"); break;
case 4: print("awesome"); break;
default: print(""); break;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论