Home >Web Front-end >JS Tutorial >js restricts the text box to only input integers or numbers with decimal points_javascript skills

js restricts the text box to only input integers or numbers with decimal points_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:02:11929browse

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.

Copy code The code is as follows:


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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn