I’ve been looking for a jQuery plugin which will allow me to turn a textbox into a numeric, ranged textbox. After searching a little around the web, experimenting with some of the alternatives without satisfaction, I found some code samples which were partially adequate and I decided on writing specific code for my own purposes.
It’s designed for something quite specific, so it lacks many options which more “generic” plugins have, but it could be of use for developers who require a simple numeric textbox limited by a certain “max number”. There’s no min number involved, but basically you can’t enter characters other than numeric, so it’ll either accept empty, zero or a positive number up to the max specified.
This is my first jQuery plugin ever. My steps were basically:
- Write jQuery-based code in my main document which performed what I wanted.
- Look up at the documentation for authoring jQuery plugins, and then I copy-pasted one of the examples which I thought suitable.
- Copy-pasted the code from step 1 onto the example’s template copied in step 2.
- Test and debug.
Here it is:
As I’m aware that this plugin lacks lots of functionality, and probably will have it’s own share of bugs, it’ll be great to receive recommendations for other plugins which support numeric and ranged input. I was hoping that jStepper would be my preferred solution as it seemed to have all that I wanted and more, but for some reason it ignores my option settings for not allowing decimals.
If you wish, you can download the code from here: jquery.numeric.js. Just make sure that you rename to js instead of doc.