JavaScript determines whether a string is numeric (integer or floating-point) __java

Source: Internet
Author: User

JavaScript isNaN (VAR) function, returns a Boolean value
Used to determine if VAR is a non-numeric value, if the Non-numeric value returns True, or False if it is not.

Cases:
var intnum = 4;
var floatnum = 3.1415;
var str1 = "I am a student";
var obj= window;
isNaN (Intnum) returns false
isNaN (Floatnum) returns false
isNaN (STR1) returns True
isNaN (obj) returns true
Intnum,floatnum are numbers, so returns false, and STR1 is a string, obj is an object, so returns true;

var intstr = "1234";
var floatstr = "3.1315";
var str2 = "3a";
var str3 = "3.1415a";
isNaN (INTSTR) returns false
isNaN (FLOATSTR) returns false
isNaN (STR2) returns True
isNaN (STR3) returns True
Here Intstr,floatstr though is a string, but intstr,floatstr are numeric strings that can be converted to numbers, so return

False, and STR2,STR3 can neither be converted from integers nor converted by floating-point numbers, so return true
How to use:

< HTML >
< head >
< title > isNaN usage </title >
< BODY >
< font color = "Red" >
< script type = "Text/javascript" > ...
<!--
var intnum = 4;
var floatnum = 3.1415;
var str1 = "I am a student";
var obj= window;
document.write (isNaN (intnum) + "<br>");//return False
document.write (isNaN (floatnum) + "<br>"); return False
document.write (isNaN (str1) + "<br>");//return True
document.write (isNaN (obj) + "<br>");//return True

var intstr = "1234";
var floatstr = "3.1315";
var str2 = "3a";
var str3 = "3.1415a";
document.write (isNaN (INTSTR) + "<br>");//return False
document.write (isNaN (FLOATSTR) + "<br>");//return False
document.write (isNaN (str2) + "<br>");//return True
document.write (isNaN (STR3) + "<br>");//return True
-->
</script >
</font >
</Body >
</HTML >

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.