var password = document.getElementById('password').value; var regPassword = "^(?!^[0-9]+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z_]{6,16}$"; var passwordFalg = password.search(regPassword); if (passwordFalg == -1) { alert("密码格式不正确,不能是纯数字或者纯字母,不能包含特殊字符,密码长度在6~16位之间!"); return; }