在客户端验证密码强度,兼容FireFox和IE
点击次数:66 次 发布日期:2008-11-06 07:56:09 作者:源代码网
|
0. 密码为空。 1. 密码长度小于六位.或者密码只有一种组合。 2. 密码长度大于五位, 且有两种组合。 3. 密码长度大于五位, 且有三种组合。 4. 密码长度大于五位,,且有四种组合。 四种组合指 数字,小写字母,大写字母,其它字符 源代码如下: 以下为引用的内容: function EvaluatePassword(word) { if (word == "") { return 0; } else if (word.length < 6) { return 1; } else { return word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|d(?![^d]*d)|[^a-zA-Zd](?![a-zA-Zd]*[^a-zA-Zd])/g).length; } } 测试代码: 以下为引用的内容: <script language="JavaScript"> function EvaluatePassword(word) { if (word == "") { return 0; } else if (word.length < 6) { return 1; } else { return word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|d(?![^d]*d)|[^a-zA-Zd](?![a-zA-Zd]*[^a-zA-Zd])/g).length; } } var test = new Array("", "a1_", "abcdef", "abcde123", "ads23%", "aA1B2^&2"); for(var i in test) { document.write(test[i] + " 的密码强度为" + EvaluatePassword(test[i]) + "<br>"); 软件开发网 www.mscto.com } </script> 源代码网推荐 源代码网供稿. |
