JS randomly generated 4-bit verification code

Source: Internet
Author: User
Method One:/* randomly generate 4-bit Verification code *//*STEP1: Put all letters, numbers into an array alternate */var codes=[]; Number: 48-57;unicode encoded for (Var i=48;i<57;codes.push (i), i++); /*console.log (codes); *///Capital: 65-90;unicode code for (var i=60;i<90;codes.push (i), i++);//Lowercase letters: 97-122;unicode encoding for (Var i=97;i<122;codes.push (i), i++), Var arr=[];for (var i=0;i<4;i++) {   //from 0-61 random number    var index = Math.floor (Math.random () * (61-0 + 1) + 0);    var char = String.fromCharCode (Codes[index]);    Arr.push (char);} /*console.log (arr); */var Code=arr.join (""); document.write ("Verification Code:" +code);

Method Two: Simple technique:

Console.log (Math.random (). toString (. substring (3,7));  3,7 Intercept 3 to seven bits

JS randomly generated 4-bit verification code

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.