How do I make a textbox take only numeric characters using jQuery? [closed]
I need to make a textbox that only allows numeric characters. I've looked through several numeric plugins and can't find one that I like. I'm looking for either a plugin recommendation with the associated URL or syntax showing how to get started on making my own plugin.
$("#testinput").keypress(function(e){
if (isNaN(String.fromCharCode(e.which))){
return false;
}
});
You can start by implementing the function with JQuery and then integrate it into a (configurable) plugin.
To handle textbox input you should intercept keydown event on textbox and then prevent the input if it's not allowed.
To write a plugin you can start from here: http://www.learningjquery.com/2007/10/a-plugin-development-pattern http://www.learningjquery.com/2009/03/making-a-jquery-plugin-truly-customizable
精彩评论