How can I restrict input to a text-box so that it accepts only numbers and the decimal point?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
The accepted solution is not complete, since you can enter multiple '.', for example 24....22..22. with some small modifications it will work as intended:
Better solution
A small correction to @rebisco's brilliant answer to validate the decimal perfectly.
If you want it for float values,
Here is the function I am using
I observed that for all the answers provided here, the things are not working if we select some portion of the text in textbox and try to overwrite that part. So I modified the function which is as below: