Js verifies whether the string is a numeric Function

Source: Internet
Author: User

Js verifies whether the string is a numeric function many times we need to verify whether the user input information is a pure number. Now we define the letters as a 0-9 number, in this way, the user input data is compared. If yes, OK.

Whether the character string is a numeric Function
A lot of time, we need to verify whether the user input information is a pure number. Now we define the number 0-9 for letters, so that we can compare the user input data.
*/

Function checkifnumber (str)
{
Var letters = "1234567890 ";
Var I;
Var c;
For (I = 0; I <str. length; I ++)
{
C = str. charat (I );
If (letters. indexof (c) <0)
Return false;
}
Return true;
}
Var tel = 123456;
If (checkifnumber (tel ))
{
Alert ('digit verification pass ');
}
Else
{
Alert ('www. bKjia. c0m. You have entered a non-digit ');
}

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.