Home > Web Front-end > JS Tutorial > Verification code for jquery to determine password strength_jquery

Verification code for jquery to determine password strength_jquery

WBOY
Release: 2016-05-16 15:31:39
Original
1993 people have browsed it

本文实例讲述了jquery判断密码强度的验证代码,分享给大家供大家参考。具体如下:
预想的效果截图如下:  

JS代码:

$('#pass').keyup(function(e) {
 var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
 var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
 var enoughRegex = new RegExp("(?=.{6,}).*", "g");
 if (false == enoughRegex.test($(this).val())) {
 $('#passstrength').html('More Characters');
 } else if (strongRegex.test($(this).val())) {
 $('#passstrength').className = 'ok';
 $('#passstrength').html('Strong!');
 } else if (mediumRegex.test($(this).val())) {
 $('#passstrength').className = 'alert';
 $('#passstrength').html('Medium!');
 } else {
 $('#passstrength').className = 'error';
 $('#passstrength').html('Weak!');
 }
 return true;
});
Copy after login

页面:

<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>
Copy after login

以上就是jquery判断密码强度的验证代码,大家可以应用到自己的项目中,希望大家喜欢。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template