<script>

    function validateForm() {
        var uname = document.forms["registration"]["uname"].value;
        var psw = document.forms["registration"]["psw"].value;
        var confirmPsw = document.forms["registration"]["confirmPsw"].value;

        if( !uppercaseRegex.test(psw) || !lowercaseRegex.test(psw) || !digitRegex.test(psw) || !specialCharRegex.test(psw))
        {
            message.textContent = "Password does not meet criteria";
            message.style.color = "red";
            return false
        }
        if (psw === confirmPsw) {
            message.textContent = "Passwords match";
            message.style.color = "green";
            return true
        } else {
            message.textContent = "Passwords do not match";
            message.style.color = "red";
            return false
        }

    }


    function checkPasswordMatch() {
        var psw = document.forms["registration"]["psw"].value;
        var confirmPsw = document.forms["registration"]["confirmPsw"].value;

        var message = document.getElementById("passwordMatchMessage");

        var uppercaseRegex = /[A-Z]/;
        var lowercaseRegex = /[a-z]/;
        var digitRegex = /[0-9]/;
        var specialCharRegex = /[!@#$%^&*()_+{}\[\]:;<>,.?~\\-]/;

        if( !uppercaseRegex.test(psw) || !lowercaseRegex.test(psw) || !digitRegex.test(psw) || !specialCharRegex.test(psw))
        {
            message.textContent = "Password does not meet criteria";
            message.style.color = "red";
            return
        }
        if (psw === confirmPsw) {
            message.textContent = "Passwords match";
            message.style.color = "green";
        } else {
            message.textContent = "Passwords do not match";
            message.style.color = "red";
        }
    }

    function checkPassword() {
            var psw = document.forms["registration"]["psw"].value;

            var conditions = document.getElementsByClassName("condition");
            var message = document.getElementById("passwordMatchMessage");

            // Check if password meets additional criteria
            var uppercaseRegex = /[A-Z]/;
            var lowercaseRegex = /[a-z]/;
            var digitRegex = /[0-9]/;
            var specialCharRegex = /[!@#$%^&*()_+{}\[\]:;<>,.?~\\-]/;

            conditions[0].classList.toggle("met", uppercaseRegex.test(psw));
            conditions[1].classList.toggle("met", lowercaseRegex.test(psw));
            conditions[2].classList.toggle("met", digitRegex.test(psw));
            conditions[3].classList.toggle("met", specialCharRegex.test(psw));
        }
</script>