Home  >  Article  >  Web Front-end  >  How to use jquery to determine whether it is a number

How to use jquery to determine whether it is a number

coldplay.xixi
coldplay.xixiOriginal
2020-12-25 09:44:142696browse

How to use jquery to determine whether it is a number: first create a new file, use the input tag to create an input box; then use the button tag to create a button, and bind the onclick click event to the button button; finally pass [test()] The method uses regular expressions to determine whether the input content is a number.

How to use jquery to determine whether it is a number

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, DELL G3 computer.

Recommended: jquery video tutorial

##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 use jquery to determine whether it is a number

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 for the following The id gets the input object.

How to use jquery to determine whether it is a number

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 use jquery to determine whether it is a number

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 use jquery to determine whether it is a number

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 use jquery to determine whether it is a number

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, it will prompt "Input is correct", otherwise, it will prompt "Please enter a number".

How to use jquery to determine whether it is a number

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 use jquery to determine whether it is a number

Related free learning recommendations: javascript(Video)

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

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