mercredi 25 novembre 2020

Error in validating my password with Javascript

I am trying to check my user inputted password with a series of if statements and boolean variables within a function. It seems like my if statements are not modifying my boolean variables. Could someone tell me why?

I was trying to use (/[a-zA-z]/).test(pValue.charAt(0))) as a boolean to see if the first character entry was a lower or upper case letter, but that didn't work either.

document.querySelector("#enter").addEventListener("click", validate);

function validate(e) {
  
  var count = false;
  var firstChar = false;
  var hasNum = false;
  var special = false;
  var pValue = document.querySelector("#passwrd").value;
  var pLength = pValue.length;
  
  console.log(pValue);
  
  console.log(pLength);
  
  if(pLength > 4 && pLength <= 8) {
    
    count = true;
    
  }
  
  if(pValue.search(e.charCode === [65 - 90]) === 0) {
    
    firstChar = true;
    
  }
  
  console.log(firstChar);
  
  for(var j = 0; j < pLength; j++) {
    
    if(pValue.charAt(j) == "$" || pValue.charAt(j) == "%" || pValue.charAt(j) == "#") {
      
      special = true;
      
    }
    
  }
  
  for(var i = 0; i < pLength; i++) {
    
    if(!isNaN(pValue.charAt(i))) {
      
      hasNum = true;
      
    }
    
  }
  
  if(count && firstChar && hasNum && special) {
    
    document.querySelector("#show_word").textContent = pValue;
    
  }
  
}

Aucun commentaire:

Enregistrer un commentaire