手机版

javascript密码强度校验代码(两种方法)

时间:2021-09-08 来源:互联网 编辑:宝哥软件园 浏览:

先看效果图:

爪哇岛描述语言密码强度校验代码,具体实现思路不多说了,请看下面代码和演示。

第一种方法:

/* *密码安全程度*返回:全部为字母或者数字,或者密码长度小于*返回:字母数字组成,或者字母特殊字符,或者数字和特殊字符*返回:字母和数字和特殊字符*/String。原型。passwordstrength=function(){ if(this。长度这个。长度=)返回;var n=(this.search(/[a-zA-Z]/)!=-) ?n=(this.search(/[-]/)!=-) ?n=(this.search(/[\~\`\!\@\#\$\%\^\\*\(\)\_\ \-\=\[\]|{\}\;\'\:\'\,\.\/\\\?]{,}/) !=-) ?返回n n n }演示

!doctype html html head meta charset=' utf-' title js密码强度/title style type='text/css ' .pw _ letter { margin-top : px;font-size : px} .pw_letter标签{左侧浮动:右边距: px光标:默认值;font-size : px线高:像素;} .pw _字母span{左侧浮动:显示:内嵌块;宽度: px高度:像素线高: px文本对齐:居中;颜色: # FFF;背景色: # CCC左边框:像素实心# FFF;} .pw _字母跨度。pw _ strong _ color {底色:绿色;}/样式/头体输入id=' password ' type=' password ' name=' password ' placeholder='密码onKeyUp=' setPasswordStrength(这。价值。trim())' div class=' pw _ letter '标签安全程度/label span class='强度'弱/span span class='强度'中/span span class='强度'强/span /div脚本类型='text/javascript' /* *密码安全程度*返回:全部为字母或者数字,或者密码长度小于*返回:字母数字组成,或者字母特殊字符,或者数字和特殊字符*返回:字母和数字和特殊字符*/String。原型。passwordstrength=function(){ if(this。长度这个。长度=)返回;var n=(this.search(/[a-zA-Z]/)!=-) ?n=(this.search(/[-]/)!=-) ?n=(this.search(/[\~\`\!\@\#\$\%\^\\*\(\)\_\ \-\=\[\]|{\}\;\'\:\'\,\.\/\\\?]{,}/) !=-) ?返回n n n}字符串。原型。trim=字符串。原型。trim | | function(){ return this.replace(/^\s | \ s $/g ' ');}函数设置passwordstrength(pwd){ var strength _ span=document。getelementsbyclassname(' strength ');对于(var I=;is trength _ span . length I){ strength _ span . item(I).' className='实力;} for(var I=;ipwd。passwordstrength();I){文档。getelementsbyclassname(“强度”).项目(一).”强度pw _ strength _ color ';} }/脚本/正文第二种方法:

爪哇岛描述语言代码如下:

脚本函数AuthPasswd(字符串){ if(字符串。长度=6){ if(/[a-Za-Z]/.测试(字符串)/[0-9] /.测试(字符串)/\W \D /.test(string)){ notice sign(1);}else if(/[a-zA-Z] /.测试(字符串)|| /[0-9] /.测试(字符串)|| /\W \D /.test(string)) { if(/[a-zA-Z] /.测试(字符串)/[0-9] /.test(string)){ notice sign(-1);}else if(/\[a-zA-Z] /.测试(字符串)/\W \D /.test(string)){ notice sign(-1);}else if(/[0-9] /.测试(字符串)/\W \D /.test(string)){ notice sign(-1);} else { note sign(0);} } } else { note sign(null);} }函数注意符号(num){ if(num==1){ $(' # weak ').CSS({背景色: ' # 009900 ' });$(“# middle”).CSS({背景色: ' # 009900 ' });$(' #强度').CSS({背景色: ' # 009900 ' });$(' #强度').html(")很强');$(“# middle”).html(" ");$(“# weak”).html(" ");}else if(num==-1){ $('#weak ').CSS({背景色: ' # ffcc 33 ' });$(“# middle”).CSS({背景色: ' # ffcc 33 ' });$(' #强度').CSS({背景色: ' ' });$(“# weak”).html(" ");$(“# middle”).html(")中');$(' #强度').html(" ");}else if(num==0) { $('#weak ').CSS({背景色: ' # DD 0000 ' });$(“# middle”).CSS({背景色: ' ' });$(' #强度').CSS({背景色: ' ' });$(“# weak”).html(")弱');$(“# middle”).html(" ");$(' #强度').html(" ");}else{ $('#weak ').html(" ");$(“# middle”).html(" ");$(' #强度').html(" ");$(“# weak”).CSS({背景色: ' ' });$(“# middle”).CSS({背景色: ' ' });$(' #强度').CSS({背景色: ' ' });} }/脚本以上通过两种方法介绍了爪哇岛描述语言密码强度校验代码,希望对大家有所帮助。

版权声明:javascript密码强度校验代码(两种方法)是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。