JavaScript Random authentication code Generation instance Code _javascript technique

Source: Internet
Author: User

Generation of random verification codes

1: The main part

<script> var code; 
    The global definition Validation code function createcode () {code = ""; 
    var codelength = 6;//The length of the authentication code var checkcode = document.getElementById ("Checkcode"); var Selectchar = new Array (0,1,2,3,4,5,6,7,8,9, ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ' 
    
     
    , ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ');//All the characters of the candidate composing the verification code, of course, can also be in Chinese for (Var i=0;i<codelength;i++) { 
    var charIndex = Math.floor (Math.random () *36); 
     
     
    Code +=selectchar[charindex]; 
    }//alert (code); 
     if (Checkcode)//Here is not very understand, there are experts can explain the next {checkcode.classname= "code"; 
    Checkcode.value = code; 
    The function validate () {var inputcode = document.getElementById ("INPUT1"). Value; if (Inputcode.length <=0) {alert ("Please enter the verification code!") 
      "); 
    document.getElementById ("INPUT1"). focus (); else if (Inputcode!= code) {alert ("Validation code input Error!) 
     "); Createcode ()//Refresh Verification Code Inputcode= ""; 
    document.getElementById ("INPUT1"). focus (); 
    }else{Document.frmRegister.submit (); 
 

 }} <script>

Then how do I put it in the validation box?

<input type= "text" id= "Checkcode" class= "unchanged" style= "width:80px" readonly/>

And then there's the judgment.

<input type= "text" onclick= "Createcode ()" id= "Input1"/>

Ok.... Get... The Onclik here is to move away as soon as you move.

The above is JS randomly generated verification code data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

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.