下面图老师小编要向大家介绍下javascript密码强度提示,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!
【 tulaoshi.com - Web开发 】
%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PasswordStrong._Default" %
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml"
head runat="server"
title/title
/head
body
form id="form1" runat="server"
div
input id="reg_passwd__" name="reg_passwd__" value="" ;="" onkeyup="update_strength('reg_passwd__','reg_passwd__strength_display__')" autocomplete="off" type="password"/
script type="text/javascript"
function update_strength(input_field_id, output_display_id)
{
var input_field = document.getElementById(input_field_id);
var output_display = document.getElementById(output_display_id);
var input_str = input_field.value;
var input_length = input_str.length;
var strength = 0;
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/) // increase strength if contains [0-9]
number_re = new RegExp("[0-9]");
if (number_re.test(input_str)) {
strength++;
}
// increase strength if contains non alpha
non_alpha_re = new RegExp("[^A-Za-z0-9]");
if (non_alpha_re.test(input_str)) {
strength++;
}
// increase strength if contains upper case
upper_alpha_re = new RegExp("[A-Z]");
if (upper_alpha_re.test(input_str)) {
strength++;
}
// increase strength if long enough
if(input_length =8) {
strength++;
}
var strength_str;
if (strength = 1) {
strength_str = 'strong style="color:blue"弱/strong';
} else if (strength = 2) {
strength_str = 'strong style="color:blue"中等/strong';
} else {
strength_str = 'strong style="color:green"强壮/strong';
}
if(input_str.length 6) {
strength_str = 'strong style="color:orange"太弱/strong';
}
output_display.innerHTML = strength_str;
}
/script
div
span密码强度: /span
span id="reg_passwd__strength_display__"
/span
/div
/div
/form
/body
/html
来源:http://www.tulaoshi.com/n/20160219/1623890.html
看过《javascript密码强度提示》的人还看了以下文章 更多>>