You can set this directly in the attributes of input
, with min=" "
and if you want a maximum number you can use the max=" "
.
It would look like this, for example:
<form action="#">
<input type="number" name="teste" min="4" max="20">
<button type="submit">Enviar</button>
</form>
If you really want to do it with Javascript, you can do a function that does the validation if the number is larger than specified. The function is called with onblur
when you leave the input field. Setting the send button initially as disabled
, and after validation if the number is higher, it enables the send button. Otherwise it does not enable the button and returns a message.
Following example:
<form action="#">
<input type="number" id="input" onblur="checaNumero()">
<button type="submit" id="botao-enviar" disabled > Enviar </button>
</form>
<script>
function checaNumero(){
var botao = document.getElementById("botao-enviar");
var input = document.getElementById("input");
var numeroMinimo = 4;
if (input.value > numeroMinimo) {
//aqui habilitamos o botão
botao.disabled=false;
} else{
alert("Número precisa ser maior que " + numeroMinimo);
}
}
</script>
Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.
–
Oh community, there was nothing beyond the criteria there goes, just wanted to know about a doubt that I could not even begin to have no idea of the logic for it, but that someone there in the community surely has.
– Lucas Figueredo
The question was closed because it has no defined criteria. It is not known whether you want the user to enter only with digits greater than four or values greater than four. For example
22
is larger than four but is not composed of digits larger than four.– Augusto Vasques