February 16 2016

Jquery only allow numeric (0-9) in HTML inputbox

Tagged Under :

jquery

Below is the function I use to only number, delete, backspace and tap are allow.
$(document).on("keydown", "#number", function(e) {
	var key = e.charCode || e.keyCode || 0;
	
	if (key == 8 || key == 9 || key == 13 || key == 46 || key == 110 || key == 190 || (key >= 35 && key <= 40) ||(key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
		return;
	} else {
		return false;
	}
});

Make a Comment

You must be logged in to post a comment.