What is the best way to restrict “number”-only input for textboxes?
I am looking for something that allows decimal points.
I see a lot of examples. But have yet to decide which one to use.
Update from Praveen Jeganathan
No more plugins, jQuery has implemented its own jQuery.isNumeric() added in v1.7.
See: https://stackoverflow.com/a/20186188/66767
Update
There is a new and very simple solution for this:
See this answer or try it yourself on JSFiddle.
jquery.numeric plugin
I’ve successfully implemented many forms with the jquery.numeric plugin.
Moreover this works with textareas also!
However, note that Ctrl+A, Copy+Paste (via context menu) and Drag+Drop will not work as expected.
HTML 5
With wider support for the HTML 5 standard, we can use
patternattribute andnumbertype forinputelements to restrict number only input. In some browsers (notably Google Chrome), it works to restrict pasting non-numeric content as well. More information aboutnumberand other newer input types is available here.