I want to restrict key strokes to only numbers (including those on the numpad), minus (-) and plus (+) signs, and commas (,).
Currently, it types twice when I input a number (e.g. 2 is displayed as 22) and replaces the current value with the new number. For plus, minus, and comma keys, it shows ½, m, and k respectively. I also need to allow common website shortcut keys like F5, Ctrl + R, Shift + R, delete, home, and end. However, I'm not sure how to unblock F5, Shift + R, and Ctrl + R.
$('body').on('keydown', 'input[name="textfield-correction-temperature"]', function(c) {
console.log(c.keyCode);
if(c.keyCode != 107 && c.keyCode != 109 && c.keyCode != 188 && c.keyCode > 31 && (c.keyCode < 48 || c.keyCode > 57)) {
return false;
} else {
var key = String.fromCharCode(c.which);
$(this).val(key);
}
});