I have input like this
<input max="100" min="0" type="number">
But in this input users can put numbers like 01 02 03 004 itp... And my question is how to prevent this? To only numbers from 0 to 100
0, 1, 2, 3 ... 100
I have input like this
<input max="100" min="0" type="number">
But in this input users can put numbers like 01 02 03 004 itp... And my question is how to prevent this? To only numbers from 0 to 100
0, 1, 2, 3 ... 100
In most cases JavaScript is the answer:
<input type="text" id="taskinput">
<script>
const input = document.getElementById('taskinput');
let lastValue = '';
input.oninput = () => {
if (!input.value) {
lastValue = '';
return;
}
const val = parseInt(input.value);
if (val > 100 || isNaN(val)) {
input.value = lastValue;
return;
}
lastValue = val;
input.value = lastValue;
}
</script>