老师,关于密码正则,
来源:3-10 作业题
qq_慕移动3101913
2019-11-07 10:21:07
一开始输入“”空格“”,密码框下面提示“请输入用户名”,删除空格输入纯数字6位密码,密码提示框不消失还在怎么办?
password.onblur = function (){//验证密码
var value = this.value;
var reg = /\S{6,20}/;
if (!reg.test(value)) {
spans[0].innerHTML = "请输用户名";
spans[0].style.marginLeft = '200px';
spans[0].style.color = 'red';
} else {
if (/^[1-9]{6,20}$/.test(value) || /^[a-zA-Z]{6,20}$/.test(value) || /^\W{6,20}$/.test(value)) {
hint[1].style.backgroundColor = 'red';
hint[2].style.backgroundColor = '#dddddd';
hint[3].style.backgroundColor = '#dddddd';
} else if (/^[1-9|a-z]{6,20}$/.test(value) || /^[\W|a-z]{6,20}$/.test(value) || /^[\W|1-9]{6,20}$/.test(value)) {
hint[1].style.backgroundColor = 'red';
hint[2].style.backgroundColor = 'orange';
hint[3].style.backgroundColor = '#dddddd';
} else if (/\W[0-9a-zA-Z]*/.test(value)) {
hint[1].style.backgroundColor = 'red';
hint[2].style.backgroundColor = 'orange';
hint[3].style.backgroundColor = 'green';
}
}
}1回答
好帮手慕慕子
2019-11-07
同学你好,建议:将你写的完整代码都粘贴过来, 便于老师帮助你准确高效的定位与解决问题
如果同学已经完成了作业可以上传作业, 标注上你的问题, 批作业的老师会针对你的整个项目给出详细的修改建议
祝学习愉快~~~~
相似问题