How To Make A Table Cell In The Editable Html Table To Accept Numbers Only (no Letters)?
I am working with HTML5, JavaScript, JQuery.
Solution 1:
There's an $.isNumeric() function in jQuery 1.7, otherwise you'll have to write your own function in Javascript - there's a few answers on that already.
Solution 2:
I think your question is very similar to question but there might be a better answer. This following fiddle works for your case. I used the same code as in the mentioned question
$(document).ready(function() {
$(".only-numbers").keydown(function(event) {
// Allow: backspace, delete, tab, escape, and enterif ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anythingreturn;
}
else {
// Ensure that it is a number and stop the keypressif (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
});
});
Post a Comment for "How To Make A Table Cell In The Editable Html Table To Accept Numbers Only (no Letters)?"