When I want to validate a form where I want a registration to start with a 1, nothing is executed for me, I attach the code.
JQUERY
function verificarMatricula () {
var matricula = $('#matricula').val()
if (matricula.length > 0) {
if (matricula[0] != 1) {
$('#mat').html('La matricula debe de iniciar con 1')
} else {
$('#mat').html('')
}
}
}
$(document).ready(function () {
$('#matricula').keyup(verificarMatricula)
})
HTML
<form action="datosre.php" method="POST" onsubmit="return validar2();" name="formulario">
<div class="grid">
<h1>Registro</h1>
<input id="_name" name="name" type="text" placeholder="Ingresa tu nombre"
onkeyup="this.value=this.value.toUpperCase()">
<input id="_Apaterno" name="Apaterno" type="text" placeholder="Ingresa tu apellido Paterno"
onkeyup="this.value=this.value.toUpperCase()">
<input id="_Amaterno" name="Amaterno" type="text" placeholder="Ingresa tu apellido Materno"
onkeyup="this.value=this.value.toUpperCase()">
<input id="matricula _email" autocomplete="off" name="email" type="text" value="" minlength="11"
maxlength="11" placeholder="Ingresa tu matricula">
<div id="mat" class="validacion"></div>
<input id="_password2" name="_password2" type="password" placeholder="Ingresa tu contraseña">
<input id="_verpass" name="_verpass" type="password" placeholder="Verifica tu contraseña">
<div id="comprobar" class="contra validacion"></div>
<button> Enviar </button>
<a href="index.php">Iniciar sesion</a>
</div>
</form>
The problem is mainly due to the id that you define in the input to validate, you have
id="matricula _email"
:should be
id="matricula"
:Make the change and the function call will
verificarMatricula()
succeed. Check out your example:Allow me to modify the code for slightly clearer functions, the condition is that if the registration is empty or does not start with 1, it shows the message.