日期:2014-05-16  浏览次数:20473 次

求个密码的正则表达式
* Must be at least 7 chars long
* Must have at least 1 special character  
* Must have at least 1 number
* Must have at least 1 alphabet
* Case Sensitive

长度不能少于7
必须有1个特殊字符
必须有1个数字
必须有一个字母
区分大小写


------解决方案--------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
function check() {
var reg = /[-\da-zA-Z`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]*((\d+[a-zA-Z]+[-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+)|(\d+[-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+[a-zA-Z]+)|([a-zA-Z]+\d+[-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+)|([a-zA-Z]+[-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+\d+)|([-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+\d+[a-zA-Z]+)|([-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+[a-zA-Z]+\d+))[-\da-zA-Z`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]*/;
var str = document.getElementById("bb").value;
var is=reg.test(str);
if(is)
{
if(str.length>=7)
{
alert("true");

else
{
alert("flase");

}
}
else
{
alert("flase");
}
}

</script>

</head>

<body > 
<div>
<input type="text" id="bb" />
<input type="button" value="aaa " onclick="check()" />
</div>

</body>
</html>
------解决方案--------------------
var reg=/^(?!\d+$)(?![A-Za-z]+$)(?![!@#$%^&*()]+$)[!@#$%^&*()a-zA-Z0-9]{7,}$/