JavaScript 密码验证 onkeydown 不起作用

我尝试实现简单的密码验证,但以下功能似乎不起作用,它们甚至没有显示在控制台中。我是否缺少一些非常简单的东西?


"user strict";

window.onload = init;

function init() {

    document.getElementById("newPassword").onkeydown = checkPassword;

    document.getElementById("confirmPassword").onkeydown = checkConfirm;

}

function checkPassword(event){

    let newPass = document.getElementById("newPassword").value;

    var passwordRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*&])[A-Za-z\d]@$!%*?&]{8,}$")

    if(!passwordRegex.test(newPass)){

        feedback.innerHTML = "'"+newPass + "' is not secure."

        let result = passwordRegex.test(newpass);

        console.log("result: " + result);

        return false;

    }

    return true;

}

function checkConfirm(event) {

    let confirmPass = document.getElementById("confirmPassword").value;

    let newPass = document.getElement("newPassword").value;

    if(newPass != confirmPassword)) {

        feedback.innerHTML = "Password does not match.";    

        return false;

    }

    return true;

}

let feedback - document.getElementById("feedback");


function newUserRequest() {


}


function checkUser() {

    let email = document.getElementById(emailUser).value;

    let password = document.getElementById("passwordUser").value;


}

<div class="itemsFormDisplay">

    <label class="detailNames">Password</label><br>

    <input id="newPassword" class="detailsFields" type="password" name="password" required>

</div>


<div class="itemsFormDisplay">

    <label class="detailNames">ConfirmPassword</label><br>

    <input id="confirmPassword" class="detailsFields" type="password" name="password" required>

</div>


料青山看我应如是
浏览 120回答 1
1回答

小怪兽爱吃肉

更改window.onload = init;为window.onload = init();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript