I wonder why HTML5 has not yet implemented this simple validation to input number
Here's my snippet. I can't enter. (period) and - (negative)
$('input[type="number"]').on('keypress', function(e){
if (e.which < 48 || e.which > 57)
{
e.preventDefault();
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" step="any" min="0" name="refund" class="form-control" >
But when I tried to enable keyCode for the period, I can input a lot of period in the text box.
$('.allow-decimal').on('keypress', function(e){
if (e.which == 190)
{
return true;
}
});