Create 2 functions that are validating an input so that only letters are not written, the problem is that I do not know why the code I am putting is not running, here I leave it.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
function soloNumeros(e) {
var key = window.Event ? e.which : e.keyCode
return (key >= 48 && key <= 57);
}
function soloPegarNumeros(n) {
permitidos = /[^0-9.]/;
if (permitidos.test(n.value)) {
alert("Solo se puede ingresar numeros");
n.value = "";
n.focus();
}
}
$("#txtDNI").on("keypress", soloNumeros(event));
$("#txtDNI").on("blur", soloPegarNumeros(this));
//$("#txtDNI").keypress(soloNumeros(event));
//$("#txtDNI").blur(soloPegarNumeros(this));
});
</script>
</head>
<body>
<input type="text" id="txtDNI" MaxLength="8" />
<br><br>
<input type="text" />
</body>
</html>