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:
JSFiddle
$('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" />
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…