- Backspace
- Delete
- Tab
- Escape
- Enter
- Ctrl+A
- Home
- end
- left
- right
Just add a class to textbox
.onlyNumbers
and paste the following jquery code :[js]
$(document).ready(function() {
$(".onlyNumbers").keydown(function(event) {
if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || (event.keyCode == 65 && event.ctrlKey === true) || (event.keyCode >= 35 && event.keyCode <= 39)) {
return;
}
else {
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
event.preventDefault();
}
}
});
});
[/js]
You can also apply this to
textarea
.Demo:
Really great feature!!!!!! Great work!
ReplyDeleteReally great
ReplyDeleteCan you pls help me with provision to accept decimal also
not working for drag'n'drop =/
ReplyDeletenice... but what about decimal value....?
ReplyDeleteAbsolutely not working fine on a azerty french keyboard where you have to press shift + nb if you want to type a number. Using keycodes is a major issue regarding the different types of keyboards.
ReplyDelete