How to check if the password fields are equal and larger than eight digits?

Asked

Viewed 522 times

1

I got the following HTML and would like there to be a check on javascript to see if in the fields the characters typed are equal and larger than eight digits, to enable the button submit.

I have a code JavaScript which checks the number of characters, but I also need you to check that the fields are equal and enable the button if everything is positive.

<script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function(){ 

document.querySelector("[name='senha_imob']").oninput = function(){
   this.style.backgroundColor = this.value.length >= 8 ? "red" : "#D9ECF1";
}    
         });
    </script>

<input name="senha_imob" type="password" class="imv-frm-campo">

<input name="rsenha_imob" type="password" class="imv-frm-campo">

<input type="submit" name="btn-entrar" value="ATUALIZAR" class="frm-botao" />
  • 3

    Gladison, your question is being denied because you didn’t submit any research or code you tried; you just posted an HTML code, and asked for the rest to be done. I suggest reading: https://answall.com/help/how-to-ask

1 answer

1


This can help you:

<input name="senha_imob" type="password" class="imv-frm-campo">

<input name="rsenha_imob" type="password" class="imv-frm-campo">

<input type="submit" name="btn-entrar" value="ATUALIZAR" class="frm-botao" disabled />

<script type="text/javascript">
	let campoSenha = document.querySelector('input[name="senha_imob"]');
	let campoConfirmarSenha = document.querySelector('input[name="rsenha_imob"]');
	let botao = document.querySelector('.frm-botao');

	campoSenha.addEventListener('input', function(){
		verificaCampos();
	});

	campoConfirmarSenha.addEventListener('input', function(){
		verificaCampos();
	});

	function verificaCampos() {
		if(campoSenha.value == campoConfirmarSenha.value && campoSenha.value.length > 8)
			botao.disabled = false;
		else
			botao.disabled = true;
	}

</script>

  • try typing the following value into the input: 1111111 see if the validation passes... I would turn the input value into String by security if(fieldNow.value == fieldNumber.value && String( fieldNew.value ).length > 8)

  • It doesn’t really pass because the input field needs to be more than 8 characters, if you only include 7 you won’t pass the validation anyway. No need to convert to string since it is already a.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.