<tfoot id='haDs0'></tfoot><legend id='haDs0'><style id='haDs0'><dir id='haDs0'><q id='haDs0'></q></dir></style></legend>

      <bdo id='haDs0'></bdo><ul id='haDs0'></ul>

      1. <small id='haDs0'></small><noframes id='haDs0'>

      2. <i id='haDs0'><tr id='haDs0'><dt id='haDs0'><q id='haDs0'><span id='haDs0'><b id='haDs0'><form id='haDs0'><ins id='haDs0'></ins><ul id='haDs0'></ul><sub id='haDs0'></sub></form><legend id='haDs0'></legend><bdo id='haDs0'><pre id='haDs0'><center id='haDs0'></center></pre></bdo></b><th id='haDs0'></th></span></q></dt></tr></i><div id='haDs0'><tfoot id='haDs0'></tfoot><dl id='haDs0'><fieldset id='haDs0'></fieldset></dl></div>

        jQuery 密码强度检查器

        jQuery password strength checker(jQuery 密码强度检查器)

        <small id='FSOlk'></small><noframes id='FSOlk'>

        <tfoot id='FSOlk'></tfoot>
          <bdo id='FSOlk'></bdo><ul id='FSOlk'></ul>

              • <i id='FSOlk'><tr id='FSOlk'><dt id='FSOlk'><q id='FSOlk'><span id='FSOlk'><b id='FSOlk'><form id='FSOlk'><ins id='FSOlk'></ins><ul id='FSOlk'></ul><sub id='FSOlk'></sub></form><legend id='FSOlk'></legend><bdo id='FSOlk'><pre id='FSOlk'><center id='FSOlk'></center></pre></bdo></b><th id='FSOlk'></th></span></q></dt></tr></i><div id='FSOlk'><tfoot id='FSOlk'></tfoot><dl id='FSOlk'><fieldset id='FSOlk'></fieldset></dl></div>

                  <tbody id='FSOlk'></tbody>
                  <legend id='FSOlk'><style id='FSOlk'><dir id='FSOlk'><q id='FSOlk'></q></dir></style></legend>
                • 本文介绍了jQuery 密码强度检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 jQuery 的新手,我编写了一个简单的函数来检查每次按键的密码强度.

                  I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress.

                  这个想法是,每次用户输入一个字符时,都会评估内容以测试他们输入的密码的强度......我相信每个人都以前见过这些.

                  The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before.

                  无论如何,我使用的逻辑是没有密码以值 1 开头.当使用小写字符时,分数增加到 2.当使用数字时,分数再次增加 1,同样当使用大写字符并且密码长度为 5 个或更多字符时.

                  Anyhow, the logic I have used is that no password begins with a value of 1. When a lower-case character is used, the score increments to 2. When a digit is used the score increments by 1 again, same for when an uppercase character is used and when the password becomes 5 or more characters long.

                  每次按下一个键时,返回的都是密码强度,从 1 到 5 的值.

                  What is returned is the strength of the password so far as a value from 1 to 5 every time a key is pressed.

                  那么,关于我的问题.我完成它的方式似乎不像 jQuery 那样......几乎就像我可能刚刚完成了直接的 javascript.我也想知道我的逻辑.我做了什么或忽略了什么?比我更聪明的人有什么建议吗?

                  So, about my question. The way that I've done it doesn't seem very jQuery like... almost like I may as well have just done straight javascript. Also I was wondering about my logic. Have I done anything done or overlooked something? Any suggestions from smarter people than myself?

                  任何建议或意见将不胜感激.

                  Any suggestions or advice would be appreciated.

                  $(document).ready(function(){
                  
                          $("#pass_strength").keyup(function() {
                  
                              var strength = 1;
                  
                              /*length 5 characters or more*/
                              if(this.value.length >= 5) {
                                  strength++;
                              }
                  
                              /*contains lowercase characters*/
                              if(this.value.match(/[a-z]+/)) {
                                  strength++;
                              }
                  
                              /*contains digits*/
                              if(this.value.match(/[0-9]+/)) {
                                  strength++;
                              }
                  
                              /*contains uppercase characters*/
                              if(this.value.match(/[A-Z]+/)) {
                                  strength++;
                              }
                  
                              alert(strength);
                          });
                       });
                  

                  推荐答案

                  最好的方法是按照 TJB 的建议使用现有的插件.

                  The best way is to take an existing plugin as TJB suggested.

                  关于代码本身的问题,一个更好的方法是这样写:

                  As to your question about the code itself, a nicer way is to write it like that:

                  var pass = "f00Bar!";
                  
                  var strength = 1;
                  var arr = [/.{5,}/, /[a-z]+/, /[0-9]+/, /[A-Z]+/];
                  jQuery.map(arr, function(regexp) {
                    if(pass.match(regexp))
                       strength++;
                  });
                  

                  (已修改以纠正语法错误.)

                  (Modified to correct syntax errors.)

                  这篇关于jQuery 密码强度检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                  AngularJs. Is it possible to deselect HTML “radio” input by click?(AngularJs.是否可以通过单击取消选择 HTML“收音机输入?)
                  Checking Value of Radio Button Group via JavaScript?(通过 JavaScript 检查单选按钮组的值?)
                  <legend id='82Vph'><style id='82Vph'><dir id='82Vph'><q id='82Vph'></q></dir></style></legend>

                      <bdo id='82Vph'></bdo><ul id='82Vph'></ul>
                        <tbody id='82Vph'></tbody>

                        <tfoot id='82Vph'></tfoot>

                          <small id='82Vph'></small><noframes id='82Vph'>

                          1. <i id='82Vph'><tr id='82Vph'><dt id='82Vph'><q id='82Vph'><span id='82Vph'><b id='82Vph'><form id='82Vph'><ins id='82Vph'></ins><ul id='82Vph'></ul><sub id='82Vph'></sub></form><legend id='82Vph'></legend><bdo id='82Vph'><pre id='82Vph'><center id='82Vph'></center></pre></bdo></b><th id='82Vph'></th></span></q></dt></tr></i><div id='82Vph'><tfoot id='82Vph'></tfoot><dl id='82Vph'><fieldset id='82Vph'></fieldset></dl></div>