jQuery 密码验证

2018-12-12 14:46 更新

jQuery Password Validation(密码验证)

jQuery Password Validation(密码验证)插件扩展了 jQuery Validate 插件,提供了两种组件:
一种评价密码的相关因素的功能:比如大小写字母的混合情况、字符(数字、特殊字符)的混合情况、长度、与用户名的相似度(可选的)。
一种使用评价功能显示密码强度的验证插件自定义方法。显示的文本可以被本地化。

您可以简单地自定义强度显示的外观、本地化消息显示,并集成到已有的表单中。

该插件目前版本是 1.0.0。

使用方式

如需使用 Password Validation(密码验证)插件,请添加一个 class "password" 到 input,同时添加显示强度的基本标记在表单的需要显示的地方:

<form id="register">
	<label for="password">Password:</label>
	<input class="password" name="password" id="password" />
	<div class="password-meter">
		<div class="password-meter-message"> </div>
		<div class="password-meter-bg">
			<div class="password-meter-bar"></div>
		</div>
	</div>
</form>

对表单应用 Validate 插件:

$(document).ready(function() {
  $("#register").validate();});

您可以重载 $.validator.passwordRating 实现不同的评价方法。或者重载 $.validator.passwordRating.messages 来提供其他消息,比如本地化。

实例演示

<!doctype html>
<html>
<head>
<meta charset="utf-8"><title>Makes "field" required to be the same as #other</title><link rel="stylesheet" href="http://jqueryvalidation.org/files/demo/site-demos.css" rel="external nofollow" target="_blank" >
 </head><body><form id="myform"><label for="password">Password</label><input id="password" name="password" /><br/><label for="password_again">Again</label><input class="left" id="password_again" name="password_again" /><br><input type="submit" value="Validate!"></form><script src="http://code.jquery.com/jquery-1.11.1.min.js" rel="external nofollow" ></script><script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js" rel="external nofollow" ></script><script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js" rel="external nofollow" ></script><script>// just for the demos, avoids form submitjQuery.validator.setDefaults({
  debug: true,
  success: "valid"});$( "#myform" ).validate({
  rules: {
    password: "required",
    password_again: {
      equalTo: "#password"
    }
  }});
</script>
</body>
</html>


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号