html5 密码强度,前端开发判断输入密码强度

/p>

判断输入密码强度

密码:

;(function($) {

$.fn.extend({

checkPsw: function() {

var streng_span = $(

’,

)

var promptmsg_div = $(

’,

)

this.parent().append(streng_span)

this.parent().append(promptmsg_div)

this.focus(function() {

$(this)

.siblings(‘.promptmsg’)

.hide()

$(this)

.siblings(‘.streng’)

.hide()

})

this.blur(function() {

var streng

var value = $(this).val()

var promptmsg = value == ” ? ‘请输入密码!’ : ”

if (value.match(/^\w+$/) == null && value != ”) {

promptmsg =

‘请输入正确的密码格式,密码格式只能包含数字,字母和下划线!’

}

if (value.match(/^\w+$/) != null && value != ”) {

promptmsg = ”

if (

value.match(/^\d+$/) != null ||

value.match(/^[a-z]+$/i) != null ||

value.match(/\_+/g) != null

) {

//密码输入的如果全是“数字”或“字母”或“下划线”

streng = ‘弱’

}

if (

value.match(/[a-z]+/gi) != null &&

(value.match(/\d+/g) != null ||

value.match(/\_+/g) != null)

) {

//密码输入的密码如果是“字母”和“数字”,或“字母”和“下划线”

streng = ‘强’

}

if (

value.match(/\d+/g) != null &&

value.match(/\_+/g) != null

) {

//输入的密码如果是“数字”和“下划线”

streng = ‘强’

}

if (

value.match(/[a-z]+/gi) != null &&

value.match(/\d+/g) != null &&

value.match(/\_+/g) != null

) {

//输入的密码如果包含“数字”和“下划线”和“字母”

streng = ‘很强’

}

if (value.length < 6) {

promptmsg = ‘输入的密码不能小于6位!’

streng = ”

$(this)

.siblings(‘.streng’)

.text(streng)

.hide()

}

if (value.length > 16) {

promptmsg = ‘输入的密码不能大于16位!’

streng = ”

$(this)

.siblings(‘.streng’)

.text(streng)

.hide()

}

}

if (promptmsg != ”) {

$(this)

.siblings(‘.promptmsg’)

.text(promptmsg)

.show()

return false

} else {

$(this)

.siblings(‘.promptmsg’)

.text(promptmsg)

.hide()

}

if (streng != ”) {

$(this)

.siblings(‘.streng’)

.text(streng)

.show()

return true

}

})

return true

},

})

})(jQuery)

$(‘.password’).checkPsw()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值