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

221
Vistas
Validation of the password field and the confirm password field

Good night! I'm developing a project for study and I really wanted to do the validation of the password field and the validation of the confirmSenha field. The idea is that when the user enters a different password, a message is returned saying that the passwords do not match. Below is the scope of my code.

function validarPasswordConfirm(password, confirmPassword) {

  var typedpassword = document.getElementsByName('password').value;
  var confirmTypedPassword = document.getElementsByName('passwordConfirm').value;

  if(typedpassword !== confirmTypedPassword) {
    return { value: false, text: 'Passwords are not the same.' }
  } else {
    return { value: true, text: '' }
  }
}

I'm trying to validate the password field with the confirmpassword field

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The function getElementsByName returns an array, so you can't access the value property like that.

I recommend use getElementById instead.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I noticed a few problems with your code.


Firstly, var is not used anymore (see why). You should use an alternative.

Alternatives for var are below.

  1. let - Use this for variables that can be changed.
  2. const - Use this for variables that cannot be changed (constant).

Secondly, getElementsByName() returns a NodeList, which is an iterable (like an array). This means that .value is undefined in a NodeList.

To fix it, change your code to below.

const typedPassword = document.querySelector("#password").value;
const confirmTypedPassword = document.querySelector("#passwordConfirm").value;
about 4 years ago · Juan Pablo Isaza 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