1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| window.onload = function () { var regtel = /^1[3|4|5|8|9]\d{9}$/ var regqq = /^[1-9]\d{4,}$/ var regnc = /^[\u4e00-\u9fa5]{2,3}$/ var regmsg = /^\d{6}$/ var regpwd = /^[a-zA-Z0-9_-]{6,16}$/ var regsurepwd = /^[a-zA-Z0-9_-]{6,16}$/
var tel = document.querySelector('#tel') var qq = document.querySelector('#qq') var nc = document.querySelector('#nc') var msg = document.querySelector('#msg') var pwd = document.querySelector('#pwd') var surepwd = document.querySelector('#surepwd') var over = document.querySelector('.over') var allSpan = document.querySelectorAll('.tip')
check(tel, regtel) check(qq, regqq) check(nc, regnc) check(msg, regmsg) check(pwd, regpwd) check(surepwd, regsurepwd)
function check(dom, reg) { dom.onblur = function () { if (reg.test(this.value)) { dom.nextElementSibling.className = 'tip tipRight' dom.nextElementSibling.innerHTML = '输入正确' } else { dom.nextElementSibling.className = 'tip tipWrong' dom.nextElementSibling.innerHTML = '请输入正确的格式' } } } surepwd.onblur = function () { if (this.value == pwd.value) { this.nextElementSibling.className = 'tip tipRight' this.nextElementSibling.innerHTML = '密码匹配正确' } else { this.nextElementSibling.className = 'tip tipWrong' this.nextElementSibling.innerHTML = '密码不匹配,再试一次' } } }
|