JS to determine whether a positive integer is the regular notation of a regular JavaScript positive integer

Source: Internet
Author: User

determines whether a positive integer

JavaScript determines whether a string of numbers is a positive integer,

The first thing to understand is these questions

    The 1:javascript will automatically block 0 of the number in front of it (I don't know if it's correct to block the word)

Console.log (000000123);//Output 123

The longest positive integer length in the 2:javascript is 21 bits, and more will be counted by scientific notation.

Here is the 21-bit console.log (1111111111111111111111)//Output 1.1111111111111111e+21//Here is 20-bit console.log (111111111111111111111 )//Output  111111111111111110000//after four bit 0 I don't know why, anyway, the 21-bit positive integer number is 0 when the last four digits are displayed.

  

    Having understood these two questions, we can begin to write!

       function Ispositiveinteger (s) {//is a positive integer            var re =/^[0-9]+[0-9]*[0-9]*$/;            return Re.test (s)        }    

Usage:

Alert (ispositivenum (number))//Returns True  -"positive integer;//returns False  -" not a positive integer;

  

JS to determine whether a positive integer is the regular notation of a regular JavaScript positive integer

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.