满意答案
wwx330
2019.06.09
采纳率:54% 等级:8
已帮助:59人
html>
testInput注册
// 校验邮箱的规则
var reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
var register = document.getElementById('register');
var userPassword = document.getElementById('userPassword');
var validatorPassword = document.getElementById('validatorPassword');
var userName = document.getElementById('userName');
var userEmail = document.getElementById('userEmail');
// 使用点击注册的时候进行校验
register.addEventListener('click', function () {
var nameValue = userName.value
var emailValue = userEmail.value
var passwordValue = userPassword.value
var validatorPasswordValue = validatorPassword.value
var isValidatorTrue = true;
// 判断用户名
if (!nameValue) {
console.log('用户名不能为空!');
isValidatorTrue = false;
return false
} else if (nameValue.length
console.log('用户名长度不能小于9位!');
isValidatorTrue = false;
return false
} else {
isValidatorTrue = true;
}
// 判断邮箱
if (!emailValue) {
console.log('邮箱不能为空!');
isValidatorTrue = false;
return false
} else if (!reg.test(emailValue)) {
console.log('邮箱不符合规则!');
isValidatorTrue = false;
return false
} else {
isValidatorTrue = true;
}
// 判断密码
if (!passwordValue) {
console.log('密码不能为空!');
isValidatorTrue = false;
return false
} if (passwordValue.length
console.log('密码长度不能小于6位!');
isValidatorTrue = false;
return false
} else {
isValidatorTrue = true;
}
// 校验密码
if (!validatorPasswordValue) {
console.log('重复密码不能为空!');
isValidatorTrue = false;
return false
} else if (validatorPasswordValue !== passwordValue) {
console.log('两次输入的密码不一致');
isValidatorTrue = false;
return false
} else {
isValidatorTrue = true;
}
if (isValidatorTrue) {
console.log('校验通过')
}
})
00分享举报