<!DOCTYPE html>
<html>
<head>
<title>正则表达式判断密码复杂度(原生JavaScript)</title>
</head>
<body>
<form id="form1" method="post" action="#">
<div class="fmfs">
<div class="fmf"><label>创建密码(至少6位):</label><br /><input type="password" id="i1" name="password" onblur="var r=this.value.length>=6?pwdRank(this.value):0;this.style.backgroundColor=(r==1?'#ccc':r==2?'#ff0':r==3?'#0f0':r==4?'#0ff':r==5?'#00f':'#fff');" /></div>
<div class="fmf"><label>重复密码:</label><br /><input type="password" id="i2" name="password1" /></div>
</div>
</form>
<pre>
<script>
/**
* 正则表达式判断密码复杂度(原生JavaScript)
*
* @param {String} 输入明文密码
*
* @return {Number} 返回 1,2,3,4,5 个级别权重的复杂度
*
* @example
* document.write(
* pwdRank("ABCdefg1234")+'\n'+
* pwdRank("aaBB11__CCDDee")+'\n'+
* pwdRank("aaBB11__CCDD")+'\n'+
* pwdRank("abA1_")+'\n'+
* pwdRank("11_")+'\n'+
* pwdRank("111aaaAAA111aaaAAA")+'\n'+
* pwdRank("AAA___AAA___AAA__")+'\n'+
* pwdRank("0123456789123")+'\n'+
* pwdRank("012345678912346789")+'\n'
* );
*/
pwdRank=function(w){
//取字符串长度
var l=w.length,
f=function(x,s){ //正则表达式判断函数
return ((eval('/'+x+'/').test(s))?1:0)
},
//求和获得4种密码字符组合方式
z=f('[0-9]',w)+f('[a-z]',w)+f('[A-Z]',w)+f('[\\W_]',w),
//只有一种组合情况下长度11位或以上才加权重 --避免0123456789这种弱密码
r=(l>10&&z==1)?z+1:z;
//任何组合情况下但有多个重复字符串减权重
if(r>1&&f('^(?:(\\w+)\\1+)+$|(\\w)\\2{2,}',w))r--;
//多种组合长度12位或以上加权重,一种组合13位或以上加权重
if((l>11&&z>1)||(l>12&&z==1))r++;
//长度14位或以上再加权重
if(l>13&&r<5)r++;
return r;
};
document.write(
pwdRank("ABCdefg1234")+'\n'+
pwdRank("aaBB11__CCDDee")+'\n'+
pwdRank("aaBB11__CCDD")+'\n'+
pwdRank("abA1_")+'\n'+
pwdRank("11_")+'\n'+
pwdRank("111aaaAAA111aaaAAA")+'\n'+
pwdRank("AAA___AAA___AAA__")+'\n'+
pwdRank("0123456789123")+'\n'+
pwdRank("012345678912346789")+'\n'
);
</script>
1=很弱
2=普通
3=中等
4=较强
5=很强
</pre>
</body>
</html>
function isIDCardCn(idValue) {
if (idValue.length != 18) return !1;
var verifyGmsfhLast = function(sVal) {
if (sVal.length != 18) return !1;
var wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1],
vi = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2],
ai = [17],
sum = 0,
remaining = 0,
verifyNum = "",
i, m;
for (i = 0; i < 17; i++) {
ai[i] = parseInt(sVal.substring(i, i + 1), 10)
}
for (m = 0; m < ai.length; m++) {
sum = sum + wi[m] * ai[m]
}
remaining = sum % 11;
if (remaining == 2) {
verifyNum = "X"
} else {
verifyNum = vi[remaining]
}
return verifyNum == sVal.substring(17, 18).toUpperCase()
},
a = idValue.match(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([\dXx])$/);
if (a != null) {
var D = new Date(a[2] + "/" + a[3] + "/" + a[4]),
B = D.getFullYear() == a[2] && (D.getMonth() + 1) == a[3] && D.getDate() == a[4]
if (!B) return !1;
}
return verifyGmsfhLast(idValue)
}
!function(s) {
var i,r = "";
for (i = 0; i < 100; i++) {
if (i < 10 && isIDCardCn(s + '0' + i)) {
r += s + '0' + i + "<br>"
} else {
if (isIDCardCn(s + i)) r += s + i + "<br>"
}
}
for (i = 0; i < 10; i++) {
if (isIDCardCn(s + i + "x")) r += s + i + 'X' + "<br>"
}
document.write(r);
}("1122331999112233");