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

1

I have the following HTML and would like a check in javascript to see if in the fields the characters entered are equal to and greater than eight digits, to enable the% / p>

I have a code submit that checks the number of characters, but I also need to verify 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" />
    
asked by anonymous 07.08.2018 / 19:34

1 answer

0

This may 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>
    
07.08.2018 / 19:54