Block +,-,e in input type number
The default behavior if you don't like the incoming key value:
HTML::
<input type="number" class="classname">
SCRIPT::
<script>
document.querySelector(".classname").addEventListener("keypress", function (evt) {
if (evt.which != 8 && evt.which != 0 && evt.which < 48 || evt.which > 57)
{
evt.preventDefault();
}
});
// 0 for null values
// 8 for backspace
// 48-57 for 0-9 numbers
</script>
HTML::
<input type="number" class="classname">
SCRIPT::
<script>
document.querySelector(".classname").addEventListener("keypress", function (evt) {
if (evt.which != 8 && evt.which != 0 && evt.which < 48 || evt.which > 57)
{
evt.preventDefault();
}
});
// 0 for null values
// 8 for backspace
// 48-57 for 0-9 numbers
</script>
Comments
Post a Comment