var tel = document.querySelector('#tel'); var qq = document.querySelector('#qq'); var nc = document.querySelector('#nc'); var mes = document.querySelector('#mes'); var pwd = document.querySelector('#pwd'); var surepwd = document.querySelector('#surepwd');
regexp(tel, regtel); // 手机号码验证 regexp(qq, regtel); // QQ验证 regexp(nc, regnc); // 昵称验证 regexp(mes, regmes); // 短信验证码验证 regexp(pwd, regpwd); // 密码验证 // 表单认证的函数 function regexp(ele, reg) { ele.onblur = function() { if (reg.test(this.value)) { // console.log('正确的'); this.nextElementSibling.className = 'success'; this.nextElementSibling.innerHTML = '<i class="success_icon"></i> 恭喜你,输入正确'; } else { // console.log('错误'); this.nextElementSibling.className = 'error'; this.nextElementSibling.innerHTML = '<i class="error_icon"></i> 格式错误'; } } };
surepwd.onblur = function() { if (this.value == pwd.value && this.value != '') { // console.log('正确的'); this.nextElementSibling.className = 'success'; this.nextElementSibling.innerHTML = '<i class="success_icon"></i> 恭喜你,输入正确'; } else { // console.log('错误'); this.nextElementSibling.className = 'error'; this.nextElementSibling.innerHTML = '<i class="error_icon"></i> 两次密码不一致'; } } }