JSFiddle - React, Tailwind, and code Playground

by David Thomas

HTML

<input id="test" type="password" />

JavaScript

function validateConditions (string, n) {
    var capital = /[A-Z]/,
        lower = /[a-z]/,
        numeric = /\d/,
        special = /[!*?$%&]/,
        tests = [capital, lower, numeric, special],
        success = tests.filter(function (validate) {
            if (validate.test(string)) {
                return true;
            }
        });
    
    return success.length >= n;
}

document.getElementById('test').addEventListener('keyup', function (e) {
    console.log(validateConditions(e.target.value, 3));
});