Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

336
Vistas
i want to check the user input in sign up form at runtime not just on clicking the submit button

I have made a sign up form with validation in username ,name ,password and confirm password all of validations are working on clicking a submit button but I want the validations on run time like if user is entering a password user should see the validations before even clicking submit button

form.addEventListener('submit', e => {
    e.preventDefault();

    checkInputs();
});

function checkInputs() {
    // trim to remove the whitespaces
    const usernameValue = username.value.trim();
    const emailValue = email.value.trim();
    const passwordValue = password.value.trim();
    const password2Value = password2.value.trim();
    var numbers = /[0-9]/;
    var char = /[!@#$%^&*()+_{}|]/;
    var pwd = /^(?=.*[a-z])/;
    var pwd1 = /^(?=.*[A-Z])/;
    var pwd2 = /^(?=.*[0-9])/;




    if (usernameValue === '') {
        setErrorFor(username, 'Username cannot be blank');
    }
    else {
        if (usernameValue.match(numbers) || usernameValue.match(char)) {

            setErrorFor(username, 'Username can only contain letters');
        } else {
            setSuccessFor(username);
        }
    }

    if (emailValue === '') {
        setErrorFor(email, 'Email cannot be blank');
    } else if (!isEmail(emailValue)) {
        setErrorFor(email, 'Not a valid email');
    } else {
        setSuccessFor(email);
    }

    if (passwordValue === '') {
        setErrorFor(password, 'Password cannot be blank');
    } else if (passwordValue.length < 8) {
        setErrorFor(password, 'Password must a minimum of 8 characters');
    }
    else if (pwd.test(passwordValue) == false) {
        setErrorFor(password,'Password must have 1 lowerCase letter');
        
    }
    
    else if (pwd1.test(passwordValue) == false) {
        setErrorFor(password,'Password must have 1 UpperCase letter');
        
    }
    else if (pwd2.test(passwordValue) == false) {
        setErrorFor(password,'Password must have 1 Number');
        
    }

    else {
        setSuccessFor(password);
    }

    if (password2Value === '') {
        setErrorFor(password2, 'Password2 cannot be blank');

    }
    else if (passwordValue !== password2Value) {
        setErrorFor(password2, 'Passwords does not match');
    } else {
        setSuccessFor(password2);
    }
}

function setErrorFor(input, message) {
    const formControl = input.parentElement;
    const small = formControl.querySelector('small');
    formControl.className = 'form-control error';
    small.innerText = message;
}

function setSuccessFor(input) {
    const formControl = input.parentElement;
    formControl.className = 'form-control success';
}

please suggest me something how can I make it work on runtime

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

To check wheather a certain field is valid or not at the time of user input

call your function using oninput event like oninput="return checkInputs()" on input field.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda