如何利用js做一个密码强度判断,下面web建站小编给大家介绍一下实现这个功能的js代码!
1、先做一个密码输入框和三个提示按钮(弱、中强)
2、js代码介绍
复制代码var text = document.getElementById("text") //密码输入框
var r = document.getElementById("ruo") //弱密码提示
var z = document.getElementById("zhong") //中密码提示
var q = document.getElementById("qiang") //强密码提示
text.onkeyup = function() {
var reg = [];
reg[0] = /[^a-zA-Z0-9]/g //特殊
reg[1] = /[a-zA-Z]/g //字母
reg[2] = /[0-9]/g //数字
var str = text.value;
var len = str.length
var sec = 0; //密码强度
if (len >= 6) {
for (var i = 0; i < reg.length; i++) {
if (str.match(reg[i])) {
sec++
}
}
}
if (sec == 0) {
r.style.backgroundColor = "white"
z.style.backgroundColor = "white"
q.style.backgroundColor = "white"
} else if (sec == 1) {
r.style.backgroundColor = "red"
z.style.backgroundColor = "white"
q.style.backgroundColor = "white"
} else if (sec == 2) {
r.style.backgroundColor = "red"
z.style.backgroundColor = "gold"
q.style.backgroundColor = "white"
} else if (sec == 3) {
r.style.backgroundColor = "red"
z.style.backgroundColor = "red"
q.style.backgroundColor = "red"
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
一款专门用于在JavaScript和TypeScript的货币处理工具库——Dinero.js
JavaScript动态日历:如何用变量num精准控制月份递增?
一款开源JavaScript库,实现图片背景色智能提取与融合——AutoHue.js
一个可以在网页上实现流畅、酷炫的过渡效果JavaScript工具库——Barba.js
标签: 密码强度
上面是“利用js做一个密码强度判断”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2890.html
workflows工作流
一张超现实主义美女照片ComfyUI工作流
一座巨大的野兽派建筑漂浮在热带风景中的贫民
一只在森林里漫步的麋鹿ComfyUI工作流
一张精心制作的熊岛复古地图ComfyUI工作流
一只白色小猫comfyui工作流
一个女人站在海边的岩石上,飞来一只鸟
一个人一条船一条鱼ComfyUI工作流
一只外星甲壳虫子ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!