自动生成8位数字密码()-其他
自动生成8位数字密码()
// 密码自动生成8位数字
automaticallyGenerate() {
//可获取的字符串
let chars = '0123456789'
let list = []
//通过随机获取八个字符串的索引下标
for (var i = 0; i < 8; i++) {
let val_1 = Math.round(Math.random() * 9)
list.push(val_1)
}
//再根据随机获取的8个字符串索引拿到这8个字符串进行拼接
let passwd = ''
for (var n = 0; n < list.length; n++) {
passwd += chars.charAt(list[n])
}
//最后判断是否符合要求(长度为8,数字组成),符合,将赋值到密码字段,不符合,重新调用该函数获取,只到符合为止
let regNumber = /^[0-9]{8}$/
if (regNumber.test(passwd)) {
this.formData.passWord = passwd
} else {
this.automaticallyGenerate()
}
},
————————
// 密码自动生成8位数字
automaticallyGenerate() {
//可获取的字符串
let chars = '0123456789'
let list = []
//通过随机获取八个字符串的索引下标
for (var i = 0; i < 8; i++) {
let val_1 = Math.round(Math.random() * 9)
list.push(val_1)
}
//再根据随机获取的8个字符串索引拿到这8个字符串进行拼接
let passwd = ''
for (var n = 0; n < list.length; n++) {
passwd += chars.charAt(list[n])
}
//最后判断是否符合要求(长度为8,数字组成),符合,将赋值到密码字段,不符合,重新调用该函数获取,只到符合为止
let regNumber = /^[0-9]{8}$/
if (regNumber.test(passwd)) {
this.formData.passWord = passwd
} else {
this.automaticallyGenerate()
}
},