密码框禁止粘贴

This commit is contained in:
姚亚男
2021-10-28 11:08:01 +08:00
parent a9e0bf7aa2
commit 06d58bbdf3
8 changed files with 342 additions and 17 deletions
+82 -1
View File
@@ -13,6 +13,8 @@ Page({
showGetCaptcha: true,
show: true, // 默认显示的是闭眼睛
showVerify: true,
vals:[],
valsVerify: []
},
bindInputPhone(e) {
@@ -84,7 +86,86 @@ Page({
}, 1000)
// 倒计时 end
},
clearrepeatval(){
this.data.vals = []
wx.showToast({
title: '禁止复制粘贴请手动输入',
icon: 'none',
duration: 2000
})
this.setData({
password: ''
})
return
},
clearrepeatvalVerify(){
this.data.valsVerify = []
wx.showToast({
title: '禁止复制粘贴请手动输入',
icon: 'none',
duration: 2000
})
this.setData({
verifyPassword: ''
})
return
},
// 新密码的输入
handlePasswordInput(e) { //禁止输入中复制粘贴
// 获取当前数组
const vals = this.data.vals
// 获取当前输入的值
const currentval = e.detail.value.replace(/\s+/g, "")
if(currentval){ // 如果值存在追加到vals中
vals.push(currentval)
}
if(vals.length == 1 ){
const v = vals[vals.length-1].length
if(v > 1){ // 如果第一个的长度就大于1 说明是粘贴过来的
this.clearrepeatval()
}
}
if(vals.length > 1){
// 如果值数组大于1 就获取最后一个值长度和倒数第二个值长度
// 比较值长度差如果大于1 则粘贴的
const lastv = vals[vals.length-1].length // 获取最后一个值的长度
const secondv = vals[vals.length-2].length // 获取倒数第二个值得长度
const dis = lastv - secondv
if(dis>1){
this.clearrepeatval()
}
}
// 最后赋值
this.data['password'] = currentval
},
// 确认新密码的输入
handleVerifyPasswordInput(e) { //禁止输入中复制粘贴
// 获取当前数组
const vals = this.data.valsVerify
// 获取当前输入的值
const currentval = e.detail.value.replace(/\s+/g, "")
if(currentval){ // 如果值存在追加到vals中
vals.push(currentval)
}
if(vals.length == 1 ){
const v = vals[vals.length-1].length
if(v > 1){ // 如果第一个的长度就大于1 说明是粘贴过来的
this.clearrepeatvalVerify()
}
}
if(vals.length > 1){
// 如果值数组大于1 就获取最后一个值长度和倒数第二个值长度
// 比较值长度差如果大于1 则粘贴的
const lastv = vals[vals.length-1].length // 获取最后一个值的长度
const secondv = vals[vals.length-2].length // 获取倒数第二个值得长度
const dis = lastv - secondv
if(dis>1){
this.clearrepeatvalVerify()
}
}
// 最后赋值
this.data['verifyPassword'] = currentval
},
// 确认
formSubmit(e) {
if(!e.detail.value.phone){