Password Validations using regex

function ValidatePassword() {

    var rules = [{
            Pattern: "[a-zA-Z]",
            Target: "UpperCase"
        },

        {
            Pattern: "[0-9]",
            Target: "Numbers"
        },
        {
            Pattern: "[!@@#$%^&*]",
            Target: "Symbols"
        }
    ];

    var password = $("#password").val();
    
    $("#Length").removeClass(password.length > 6 ? "fa-times" : "fa-check");
    $("#Length").addClass(password.length > 6 ? "fa-check" : "fa-times");
    for (var i = 0; i < rules.length; i++) {
        $("#" + rules[i].Target).removeClass(new RegExp(rules[i].Pattern).test(password) ?
            "fa-times" :
            "fa-check");
        $("#" +
            rules[i].Target).addClass(new RegExp(rules[i].Pattern).test(password) ? "fa-check" :
            "fa-times");
    }
} 
$(document).ready(function () {
    $("#password").on('onkeypress', ValidatePassword)

});

Validations not work according to rules and pattern ….. and i am using the onkrypress and these validations shows when page is reload..