It also blocks when you type into a field using the attribute max
, but the blocking action is only validated when you are calling the action of Submit in your form, if the value is above the limit value max
, a similar warning will be displayed below:
<!DOCTYPE html>
<html>
<body>
<h2>Exemplo stackoverflow.com</h2>
<form action="/minha_pagina.php">
<input type="number" name="number" min="0" max="25"><br><br>
<br><br>
<input type="submit">
</form>
</body>
</html>
Now, if you want to do this validation at the time of completing the form, you can use the function onkeyup
and adapt to how you want it to work, or follow the example of @Sorack using the function onchange
.
Take a look at the link, I think it might help you: https://stackoverflow.com/questions/8761852/maximum-and-minimum-values-in-a-textbox
– Shinforinpola
One tip I’d give is not to use the
type
number
, if you expect to have Safari users in your application– Shinforinpola