Home > Web Front-end > JS Tutorial > body text

Comparison of two methods using JS to determine whether a number is a combination of numbers and decimal points (isNaN and one-by-one judgment)_javascript skills

WBOY
Release: 2016-05-16 18:45:41
Original
1120 people have browsed it

Here are some examples: If you have a better method, I hope you will come up with a better method.
1: isNaN method:
isNaN() means non-number. If a number is passed in, it will return false. If it is not a number, it will return true.
[If it is empty, it will also return true, as will a dot. Return true, click a number combination to return false, indicating that it is a number]

Copy code The code is as follows:



------------- ------------------Example--------------------------------

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

Two: One-by-one comparison method .
Just give an example:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
] Summary: Method 2 If you always enter decimal points, the prompt will be correct. But not in the 1st one. As long as you don't meet the format of the numbers, he won't let you pass.
Related labels:
js
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