[Solved] Form Password Validation without using regex [duplicate]


As you now accepted to use RegEx, I adapted the solution based on this post https://stackoverflow.com/a/16707675/4339170:

function validate() {
  var p = document.getElementById('pass').value
  var errors = []

  //if (p.length < 8) {
  //  errors.push("Your password must be at least 8 characters")
  //}
  if (p.search(/[a-z]/) < 0) {
    errors.push("Your password must contain at least one lowercase letter.")
  }
  if (p.search(/[A-Z]/) < 0) {
    errors.push("Your password must contain at least one uppercase letter.")
  }
  if (p.search(/[0-9]/) < 0) {
    errors.push("Your password must contain at least one digit.")
  }
  if(p.search(/[\!\@\#\$\%\^\&\*\(\)\_\+\.\,\;\:\-]/) < 0) {
    errors.push("Your password must contain at least one special character.")
  }
    
  if (errors.length > 0) {
    document.getElementById("errors").innerHTML = errors.join("<br>")
    return false;
  }
  return true;
}
<label>
  Password :
  <div>
    <input type="password" placeholder="Input Password" id="pass" name="pass">
  </div>
</label>
<input type="button" value="Submit" id="submit" onClick="validate()">
<div id="errors"></div>

1

solved Form Password Validation without using regex [duplicate]