The question I have is how to make it so that in a text box where a name will be entered, the user, no matter how hard he tries, can not enter numbers in the text box, I want to do it with Jquery without using methods or functions.
I have a code with which I started, so far I have only been able to validate that the user has entered letters or numbers, but the moment I mix letters with numbers he takes it as if it were only letter
What I want to do is that the user in that text box can not enter numbers:
My html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Practica con jquery</title>
<link rel="stylesheet" type="text/css" href="plugins/BootsTrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/estilo.css">
</head>
<body>
<main>
<div class="titulo">
<h2>Formulario de prueba</h2>
</div>
<form action="#" method="POST" class="formulario">
<label>Nombre: </label>
<input type="text" id="txtNombre" name="txtNombre" placeholder="Ingrese su nombre"><p id="pp"></p>
<label>Apellido: </label>
<input type="text" id="txtApellido" name="txtApellido" placeholder="Ingrese su Apellido">
<label>correo: </label>
<input type="text" id="correo" name="correo" placeholder="[email protected]">
<input type="submit" id="enviar" name="enviar" class="btn btn-success" value="Enviar">
</form>
<button id="buton">Hola</button>
</main>
<script type="text/javascript" src="plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="plugins/BootsTrap/js/bootstrap.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>
My code in Jquery:
$(document).ready(function () {
var nombre = document.getElementById('txtNombre');
nombre.addEventListener('keyup', function() {
var nom = document.getElementById('txtNombre').value;
if (isNaN(nom)){
var r= "Este es un valor";
$('#pp').html(r);
}else{
if (Number(nom)){
$('#pp').html("Por favor no ingrese numeros");
}
}
});
});
the p-label is to test how I get the values