Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!