Nonsense not to say, realize the function of JS login Verification code need the following two steps, the concrete realization process is as follows:
1.js
var code= ""; The global definition validation code
function Createcode () {
code = "";
var codelength = 6;//The length of the authentication code
var checkcode = document.getElementById ("Checkcode");
Checkcode.value = "";
var Selectchar = new Array (0,1,2,3,4,5,6,7,8,9, ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' J ', ' K ', ' L ', ' M ', ' N ', ' P ', ' Q ', ' R ', ' S ' , ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ';
for (Var i=0;i<codelength;i++) {
var charIndex = Math.floor (Math.random () *32);
Code +=selectchar[charindex];
}
if (code.length!= codelength) {
createcode ();
}
document.getElementById ("Checkcode"). InnerHTML = code;
function Validate () {
var inputcode = document.getElementById ("Checknum"). Value.touppercase ();
if (Inputcode.length <=0) {
alert ("Please enter the verification code!") ");
return false;
}
else if (Inputcode!= code) {
alert ("Validation code input Error!) ");
Createcode ();
return false;
}
else {
alert ("Verify code passed!") ");
return true;
}
2.html
<body onload= "Createcode ();" >
<input type= "text" value= "id=" Checknum "/> <a id=
" Checkcode "onclick=" Createcode () "></ a>
<input type= "button" class= "Btncheck" "id=" Gotocheck "value=" verify "onclick=" Validate (); "/>
The above is a small series to introduce the JavaScript login verification code to achieve, I hope to help you, if you have any questions please give me a message, small set will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!