function checkStrong(sPW){
if(sPW.length==0){
return -1;
}
if (sPW.match(/[0-9]/ig) || sPW.match(/[a-zA-Z]/ig)){
return 1;
}
if (sPW.match(/[0-9]/ig) && sPW.match(/[a-zA-Z]/ig)){
return 2;
}判断密码强弱
第一个if 判断如果输入的密码 是数字或者是字母其中之一 返回1(就是弱)
第二个判断 如果是字母,数字都有 返回2 (强)但为什么实际运行的时候 我输入的密码是 数字+字母 还是弱呢?如果想要实现 输入的数字或字母 之一 是弱
两者都有 是强 该怎么写呢
if(sPW.length==0){
return -1;
}
if (sPW.match(/[0-9]/ig) || sPW.match(/[a-zA-Z]/ig)){
return 1;
}
if (sPW.match(/[0-9]/ig) && sPW.match(/[a-zA-Z]/ig)){
return 2;
}判断密码强弱
第一个if 判断如果输入的密码 是数字或者是字母其中之一 返回1(就是弱)
第二个判断 如果是字母,数字都有 返回2 (强)但为什么实际运行的时候 我输入的密码是 数字+字母 还是弱呢?如果想要实现 输入的数字或字母 之一 是弱
两者都有 是强 该怎么写呢
if (sPW.match(/[0-9]/ig) && sPW.match(/[a-zA-Z]/ig)){
return 2;
}
if (sPW.match(/[0-9]/ig) || sPW.match(/[a-zA-Z]/ig)){
return 1;
}
if(sPW.length==0){
return -1;
}
if (sPW.match(/[0-9]/ig) && sPW.match(/[a-zA-Z]/ig)){
return 2;
}
if (sPW.match(/[0-9]/ig)|sPW.match(/[a-zA-Z]/ig)){
return 1;
}这样吧 虽然不好 但是是对的
那么永远都倒不了第三步了
function checkStrong(sPW){
if(sPW.length==0){
return -1;
}
if (sPW.match(/[0-9]/ig) && sPW.match(/[a-zA-Z]/ig)){
return 2;
}
if (sPW.match(/[0-9]/ig) || sPW.match(/[a-zA-Z]/ig)){
return 1;
}把if (sPW.match(/[0-9]/ig) && sPW.match(/[a-zA-Z]/ig))
与if (sPW.match(/[0-9]/ig) || sPW.match(/[a-zA-Z]/ig))的位置换一下
即
var a = sPW.match(/[0-9]/ig)
var b = sPW.match(/[a-zA-Z]/ig)if((a&&!b) || (!a&&b))
if(sPW.match(/[0-9]/ig) ^ sPW.match(/[a-zA-Z]/ig))