JS to determine whether it is a number, whether it is an integer, whether it is a floating point

Source: Internet
Author: User

1, JS judge whether it is a number, whether it is an integer, whether it is a floating point

Regular Expression methods

function checkrate (input)
{
var re =/^[0-9]+.?   [0-9]*$/; Determines whether a string is a number//positive integer/^[1-9]+[0-9]*]*$/
if (!re.test (Input.rate.value))
{
Alert ("Please enter a number (example: 0.02)");
Input.rate.focus ();
return false;
}
}

The following is a common function notation

function Baseisnotnum (thenum)
{
Determine whether a number
if (Basetrim (thenum) = = "")
return true;
for (Var i=0;i<thenum.length;i++) {
Onenum=thenum.substring (i,i+1);
if (onenum< "0" | | onenum> "9")
return true;
}
return false;
}

function Baseisnotint (Theint)
{
Determines whether an integer
Theint=basetrim (Theint);
if ((theint.length>1 && theint.substring (0,1) = = "0") | | Baseisnotnum (Theint)) {
return true;
}
return false;
}

function Baseisnotfloat (thefloat)
{
Determine whether a floating-point number
Len=thefloat.length;
dotnum=0;
if (len==0)
return true;
for (Var i=0;i<len;i++) {
Onenum=thefloat.substring (i,i+1);
if (onenum== ".")
dotnum++;
if ((onenum< "0" | | onenum> "9") && onenum!= ".") | | DOTNUM>1)
return true;
}
if (len>1 && thefloat.substring (0,1) = = "0") {
if (thefloat.substring)! = ".")
return true;
}
return false;

IsNaN function
IsNaN (expression:object): Boolean

Evaluates the parameter and returns True if the value is NaN (not a number). This function can be used to check whether a mathematical expression was successfully evaluated as a number.

Availability: Flash Player 5;actionscript 1.0

Parameters
Expression:object-The Boolean value, variable, or other expression to be evaluated.

Return
Boolean-A Boolean value.

Example:

if (IsNaN (Document.login.imgcode.value)) {
Alert (' Verification code must be a number! ‘)
Document.login.imgcode.focus ();
return false;
}

2, <a href= "Javascript:history.back ( -1)" > Back </a>

Reprinted from http://java-admin.iteye.com/blog/507963, thanks to java-admin for sharing.

JS to determine whether it is a number, whether it is an integer, whether it is a floating point

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.