I have a text input
which I want to limit to only numbers. No other characters. I also want to limit from 0 - 255.
If a an 'illegal' char, or amount is entered, I want it to wait a second then delete that character or number. I was so far able to get the illegal characters.
Here's what I want to do:
- Make it wait a second, then delete it.
- Limit number from 0 - 255.
If more than 255 gets entered, I just want the last digit to wait, then delete itself. Just like the 'illegal' chars.
I already got the illegal character implemented. Here's the code:
$('input[name="number"]').keyup(function(e) {
if (/\D/g.test(this.value)) {
// Filter non-digits from input value.
this.value = this.value.replace(/\D/g, '');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="number" />
Try using
if
condition to check ifthis.value
is greater than255
, if true , setthis.value
to first two characters of input usingString.prototype.slice()
Try using
setTimeout()