How to validate username and navigate to another page : Trying to validate username and password 

 let passwordInput = document.getElementById('password').value;
 let userName = document.getElementById('userName').value;

function validateLogin(){

    event.preventDefault();

  // Set errors to an empty array
  let errors = [];

    // Conditions for password validation   

    if(passwordInput.length < 8) {
        errors.push('Your password must be at least 8 characters long')
    }
    if(passwordInput.search(/[a-z]/) < 0) {
        errors.push('Your password must cotain at least one lowercase letter')
    }
    if(passwordInput.search(/[A-Z]/) < 0) {
        errors.push('Your password must conatin at least one uppercase letter')
    }
    if(passwordInput.search(/[0-9]/) < 0) {
        errors.push('Password must contain at least one number!')
    }
    if(passwordInput.search(/[\!\@\#\$\%\^\&\*\(\)\_\+\.\,\;\:\-]/) < 0) {
        errors.push("Your password must contain at least one special character.")
    }

    // Login
    if (errors.length > 0) {
        document.getElementById("errors").innerHTML = errors.join("<br>")
        return false;
    } else if(!errors && userName.value){
        console.log('Youre logged in!')

    }
};
``