Home > Web Front-end > JS Tutorial > How to determine whether it is a number in jquery

How to determine whether it is a number in jquery

coldplay.xixi
Release: 2020-11-30 14:40:01
Original
6205 people have browsed it

Jquery method to determine whether it is a number: first use the input tag to create a text box and create a button button; then obtain the object through the id value of the text box, use the val method to obtain the input content of the text box; and finally use The [test()] method uses regular expressions to determine whether it is a number.

How to determine whether it is a number in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

How to use jquery to determine whether it is a number:

1. Create a new html file, named test.html, to explain how to use jquery to determine whether it is a number.

How to determine whether it is a number in jquery

2. In the test.html file, use the input tag to create an input box and set its id to myinput, which is mainly used to obtain the input object through the id below.

How to determine whether it is a number in jquery

3. In the test.html file, use the button tag to create a button with the button name "Judge whether it is a number".

How to determine whether it is a number in jquery

4. In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the isnum() function .

How to determine whether it is a number in jquery

5. In the js tag, create the isnum() function. Within the function, obtain the input object through the id value of the input (myinput). Then use the val() method to obtain the input content, and write a regular expression to verify the number "/^[1-9][0-9] $/gi".

How to determine whether it is a number in jquery

6. In the isnum() function, use the if statement and use the test() method to use regular expressions to determine whether the input content is a number. If it is a number, then It prompts "Input is correct", otherwise, it prompts "Please enter a number".

How to determine whether it is a number in jquery

7. Open the test.html file in the browser, enter the content in the text box, click the button to see the effect.

How to determine whether it is a number in jquery

Related learning recommendations: js video tutorial

The above is the detailed content of How to determine whether it is a number in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template