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 script 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("weird..."); break;

case 1: print("weak"); break;

case 2: print("ok"); break;

case 3: print("strong"); break;

case 4: print("awesome"); break;

default: print("weird..."); break;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值