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 ||
Here is a working demo that checks whether the number is valid or not and also doesn't allow multiple signs:
$("#num").on('keyup', function() { if ($.isNumeric($(this).val())) { console.log('Valid!'); } else { console.log('Invalid!'); } });