a similar code checks a text string with a different regular routine with a bang, I will not say that the code is super but it works, when checking the password and replacing the regular, nothing works, the question is in the regular database, or is the password not readable because the password type? or something else?


<div class="rov"> <div class="col-md-3"> <label for="pass_1">Пароль</label> </div> <div class="col-md-7"> <input type="password" onkeyup="ValidPassw()" id="pass_1" class="form-control" placeholder="Пароль" > </div> <div class="col-md-1"> <span class="glyphicon glyphicon-ok" style="display:none;color:green;" aria-hidden="true" id="okPass"></span> <span class="glyphicon glyphicon-remove" style="display:none;color:red;" aria-hidden="true" id="noPass"></span> </div> </div> 

  <script type="text/javascript"> function ValidPassw() { var P = ((?=.*\d)(?=.*[az])(?=.*[AZ]).{8,15}) ; var Pass = document.getElementById('pass_1').value; var valid = P.test(pass); if (valid) { document.getElementById('okPass').style.display = 'block'; document.getElementById('noPass').style.display = 'none'; } else { document.getElementById('okPass').style.display = 'none'; document.getElementById('noPass').style.display = 'block'; } return valid; }; </script > 
  • it is better to choose the name of variables and functions so that the first word is in lower case (for example, camelCase). - darkwoolf

1 answer 1

This is how it should work. What would be a green cross, change the regular expression.
PS For processing with each click, it is better to use oninput

 function ValidPassw() { var pass = document.getElementById('pass_1').value; if (/((?=.*\d)(?=.*[az])(?=.*[AZ]).{8,15})/.exec(pass)) { document.getElementById('okPass').style.display = 'block'; document.getElementById('noPass').style.display = 'none'; }else{ document.getElementById('okPass').style.display = 'none'; document.getElementById('noPass').style.display = 'block'; }; return false; }; 
 <div class="rov"> <div class="col-md-3"> <label for="pass_1">Пароль:</label> </div> <div class="col-md-7"> <input type="password" oninput="ValidPassw()" id="pass_1" class="form-control" placeholder="Пароль"> </div> <div class="col-md-1"> <span class="glyphicon glyphicon-ok" style="display:none;color:green;" aria-hidden="true" id="okPass">X</span> <span class="glyphicon glyphicon-remove" style="display:none;color:red;" aria-hidden="true" id="noPass">X</span> </div> </div>