How can I know if a input
text type has numbers?
I have the following code
Well here I have a portion of code to understand what I want to do
$('#enviar').on("click", function() {
alert("Estoy dentro");
if ( typeof $("#nombre").val().trim() === 'string') {
alert("No se permite numeros");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="nombre" name="nombre" value="Pepe123">
<input type="submit" id="enviar" name="enviar" value="enviar">
input
At the time of sending, validate that if there is a number in the chain
A simple regular expression such as can be used
\d
to check if the string contains at least one number.The implementation would be like this:
You can solve your problem using regular expressions, here is an example to count the number of numbers in a string.
I hope it helps you. Cheers