// numeric extension
jQuery.fn.onlyNumeric = function () {
return this.each(function () {
$(this).keydown(function (e) {
var key = e.which || e.keyCode;
if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
key >= 48 && key <= 57 || key >= 96 && key <= 105 ||
key == 8 || key == 13 || key == 46 ||
key == 35 || key == 36 || key == 37 || key == 39)
return true;
return false;
});
});
};
// use it in your input text box
$('#input_box').onlyNumeric();
A expert on system architect with full SDLC and Agile development experience. Skills: , C# C++ Scrum OOA/OOD javascript ASP.Net MVC XML, HTML Web Service, RESTful, WCF, Android and etc. Email me if you need help on development.
Tuesday, 8 November 2011
JQuery extension: numeric only input text
Here is the simply but re-usable approach, IMO: create an jquery numeric extension and then use the numeric extension in your input text box:
Labels:
javascript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment