JS determines whether it is a number, whether it is an integer, or whether it is a floating-point code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax code example function it is javascript return string

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

The following is a normal function
to copy the code as follows:
function Baseisnotnum (thenum)
{
//judge whether the 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)
{
//To determine whether it is an integer
Theint=basetrim (Theint);
if (theint.length>1 && theint.substring (0,1) = = "0") | | Baseisnotnum (Theint)) {
return true;
}
return false;
}
Function Baseisnotfloat (thefloat)
{
//determine if 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 (1,2)!= ".")
RetuRN true;
}
return false;

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.