Here is a function you can use.
function checkRegex(string) { var checkSpecial = /[*@!#%&()^~{}]+/.test(string), checkUpper = /[AZ]+/.test(string), checkLower = /[az]+/.test(string), r = false; if (checkUpper && checkLower && checkSpecial) { r = true; } return r; }
and then check if this is true or false.
var thisVal = document.getElementById('password').value; var regex = checkRegex(thisVal);
If var regex
is true
, then the condition is true
.
source share