Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
How to check if a string is 8 digits long?

Tell me how to do it correctly Checking less than 8 characters. The first time I just did it on an empty line. Next, there is a check of less than 8 characters, it is lit red, if more, it is lit green. The problem is how to make it less than 8 digits and turn red. And when it is greater than or equal to 8 digits, it burned green.

function validatePassword(password) {
            const reg = (/^(?=.*[0-9]{8,})$/);
            return reg.test(String(password).toLowerCase());
        };  
    const checkPassword = () => {
            const inputPassword = document.querySelector('.form__input-password');
            const inputPasswordText = inputPassword.value
            const examValidatePassword = validatePassword(inputPasswordText);
            const passwordStar = document.querySelector('.form__input-password-star');
            const passwordTitle = document.querySelector('.form__password-title');
            const textPasswordWrong = document.querySelector('.form__input-password-validate-text-wrong');
        
            if (inputPasswordText.length === 0) {
                inputPassword.style.border = '1px solid #ff0000';
                passwordStar.style.color = 'red';
                passwordStar.style.opacity = '100'
                passwordTitle.style.color = 'red';
                textPasswordWrong.style.opacity = '100';
                textPasswordWrong.innerHTML = '* Поле обязательно для заполнения';
                checkValidatePass = false;
                userPassword = "";
            } else if (examValidatePassword str.length => 8 ) {
                inputPassword.style.border = '1px solid #ff0000';
                passwordStar.style.color = 'red';
                passwordStar.style.opacity = '100';
                passwordTitle.style.color = 'red';
                textPasswordWrong.style.opacity = '100';
                textPasswordWrong.innerHTML = '* Пароль должен содержать как минимум 8 символов';
                checkValidatePass = false;
                userPassword = "";
            } else {
                inputPassword.style.border = '1px solid green';
                passwordStar.style.color = '#787878';
                passwordTitle.style.color = 'green';
                passwordStar.style.opacity = '0';
                textPasswordWrong.style.opacity = '0';
                checkValidatePass = true;
                userPassword = inputPasswordText;
            }
        };
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda