$('input[name="test"]').bind('keydown', function(e) {
var keyCode = (e.which) ? e.which : event.keyCode
return !(keyCode > 31 && (keyCode < 48 || keyCode > 57));
});
This code validates that the data entry contains only numbers, but I need it to accept numbers and the character -
Thank you for your cooperation
In order for the hyphen(-) to be accepted, the Key Code is 189, therefore we will validate that it also takes that key into account:
Compare keyCode with: 189 , which is the middle dash code (" slash ") and/or with 109 which is the minus sign code (" NumpadSubtract ")