I have this code that only permits numbers to be entered in an input field on keypress()
if (e.which != 8 && e.which != 0 && (e.which < 48 ||
This solution prevents double minuses or dots.
Just add number to input class.
$("input.number").on('keypress', function(e) {
var caret = e.target.selectionStart;
var nowStr = $(this).val().substr(0, caret) + String.fromCharCode(e.which) + $(this).val().substr(caret);
if (!$.isNumeric(nowStr)) e.preventDefault();
});