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!