Home > Article > Web Front-end > js restricts the text box to only input integers or numbers with decimal points_javascript skills
When doing form verification, will you encounter verification that only numbers can be filled in a certain input box? Only integer numbers or numbers with decimal points are allowed to be entered. The following code may help you! The form has been fully verified by defining onkeypress, onkeyup, and onblur events for the current input box, and the results are very reliable.
The following is a brief explanation of onkeypress, onkeyup, and onblur events.
The onkeypress event occurs when a keyboard key is pressed and a key is released.
The onkeyup event occurs when a keyboard key is released.
The onblur event occurs when an object loses focus.
Another thing to note is that if a form needs to be strictly verified, double verification must be done on the client and server. The client verification is done above. If someone knows a little bit about programming, they can easily bypass this verification code. If there is no verification on the server side, it will easily cause problems.
The above is the entire content of this article, I hope you all like it.