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
Just need to apply this method in Jquery and you can validate your textbox to just accept number with a decimal only.
Please see working demo here
here is script that cas help you :
Following code worked for me
The input box with "onkeypress" event as follows
The function "isNumberKey" is as follows
Are you looking for something like this?
Is this what you're looking for?
I hope it helps.
EDIT: I edited my example above so that there can only be one period, preceded by at least one digit and followed by at least one digit.
For Decimal numbers and also allowing Negatives numbers with 2 places for decimals after the point... I modified the function to: