In the previous article "JavaScript How to Click to Delete an Extension and Get the File Name" I introduced to you how to click to delete the extension and get the file name through javascript. Friends in need can Go read and find out~
The theme of this article is to teach you how to use javascript to limit the input box to only allow integers and decimal points, and not allow the use of any other symbols.
Let me introduce two implementation methods to you:
The first method:
The running results are as follows:
In the above code example:
RegExp is used to validate the input.
Every time a character is entered, the entire input is matched against a RegExp to check for validity.
If valid, the character is valid and added to the input, otherwise it is invalid.
Second method:
The running results are as follows:
In In the above code example:
Every time a character is entered, it will be checked whether the character is valid.
This example also checks the number of decimal places entered. One cannot enter 2 decimal places.
If the character is valid, it is added to the input, otherwise it is invalid.
Finally, I would like to recommend "JavaScript Basics Tutorial" ~ Welcome everyone to learn ~
The above is the detailed content of JavaScript restricts the input box to only allow integers and decimal points (two methods). For more information, please follow other related articles on the PHP Chinese website!