WEB开发网
开发学院网页设计JavaScript javascript密码强度提示 阅读

javascript密码强度提示

 2008-08-18 19:59:58 来源:WEB开发网   
核心提示:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PassWordStrong._Default" %>&l

<%@ 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;

   // 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>

Tags:javascript 密码 强度

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接