2
I am implementing a function to change the password of the logged in user. When I load the user password into the input component it does not validate the loaded password, which is outside the rule established by the function below. I would like the password to be validated by loading the modal. Currently my function only validates when I delete the component data and re-focus.
Could someone help me ??
That’s my job in JS:
$('#inpSenha').keyup(function() {
var value = $(this).val();
var letras,
numeros,
letrasMaiusculas,
especial;
if (/[a-z]/gm.test(value)) {
letras = " ";
} else {
letras = "Letras minúsculas";
}
if (/[0-9]/gm.test(value)) {
numeros = " ";
} else {
numeros = "Números";
}
if (/[A-Z]/gm.test(value)) {
letrasMaiusculas = " ";
} else {
letrasMaiusculas = "letras maiúsculas";
}
if (/[!@#$%*()_+^&{}}:;?.]/gm.test(value)) {
especial = " ";
} else {
especial = "Caracteres especiais não alfaNuméricos";
}
$('p').html("A senha deve possuir: " + letras + "|" + numeros + "|" + letrasMaiusculas + "|" + especial)
});
My component is like this:
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modalAlterarUsuario" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div style="color: white; background-color: #0c4677" class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">
<strong>Preferências</strong>
</h3>
</div>
<div class="modal-body">
<form novalidate="novalidate" data-toggle="validator" name="frmUsuario" id="formCadastro" role="form">
<div class="row">
<div>
<div class="form-group col-md-3">
<div class="form-group" style="height: 200px;">
<input class="hide" type='file' id="inputFile" onchange="readURL(this);" />
<img title="Clique para alterar a imagem" id="imagemUsuario" class="img-responsive img-circle" src="{{usuario.fotoUsuario}}" style="width: 180px;" ng-model="usuario.fotoUsuario" onerror="this.src='./imagem/imgNaoDisponivel.jpg'" />
</div>
</div>
</div>
<div class="form-group col-md-4">
<label>Login:</label>
<input maxlength="20" disabled="disabled" type="text" class="form-control" ng-model="usuario.login" />
</div>
<div class="form-group col-md-4">
<label>Nome:</label>
<input maxlength="30" type="text" class="form-control" ng-model="usuario.nome" />
</div>
<div class="form-group col-md-4">
<label>E-mail:</label>
<input maxlength="100" type="email" class="form-control" ng-model="usuario.email" />
</div>
<div class="form-group col-md-4">
<label>Senha:</label>
<input id="inpSenha" required="required" type="password" class="form-control" ng-model="usuario.senha" autofocus="autofocus" />
<span id="numero">A senha deve conter pelo menos um número.</span>
<br></br>
<span id="maiuscula">A senha deve conter pelo menos uma letra maiúscula.</span>
<br></br>
<span id="minuscula">A senha deve conter pelo menos uma letra minúscula.</span>
<br></br>
<span id="seis">A senha deve conter no mínimo 6 caracteres.</span>
<br></br>
<span id="especial">A senha deve conter pelo menos um caractere especial não alfanumérico. </span>
<br></br>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button style="background-color: #b51e27; color: white;" type="button" class="btn btn-default " id="btnSalvar" data-dismiss="modal" ng-click="salvarUsuario()">Salvar</button>
<button style="background-color: #b51e27; color: white;" type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
</div>
</div>
</div>
</div>
Include more content from your html and js, you are somewhat confused to understand the current behavior and what you want
– Leandro Angelo
Eduardo segue jsfiddle: http://jsfiddle.net/1aeur58f/1013/.
– Matheus Miranda
@Matheusmiranda It worked perfectly!! puts as answer. Thank you !
– Eduardo Krakhecke
I made another code, look at my answer as it turned out. , it validates the password when loading modal.
– Matheus Miranda