码迷,mamicode.com
首页 > Web开发 > 详细

JS简单验证password强度

时间:2015-04-01 13:10:16      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

<input type="password" id="password" value=""/><button id="validate">验证</button>
<script type="text/javascript">
	$("#validate").click(function(){
		if(isSimplePwd($("#password").val())<3){
			alert("密码过于简单!");
		}
	})
	/**
	*简单验证密码强度
	*必须包括数字、小写字母、大写字母、特殊字符 其三
	*假设返回值小于3 则说明密码过于简单 
	*/
	function isSimplePwd(s){
		if(s.length<6){
			return 0;
		}
		var ls = 0;
		if(s.match(/([a-z])+/)){
			ls++;
		}
		if(s.match(/([0-9])+/)){
			ls++;
		}
		if(s.match(/([A-Z])+/)){
			ls++;
		}
		if(s.match(/[^a-zA-Z0-9]+/)){
			ls++;
		}
		return ls;
	}
</script>


JS简单验证password强度

标签:

原文地址:http://www.cnblogs.com/gcczhongduan/p/4383460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!