Implementation of JavaScript Login verification Code _javascript skills

Source: Internet
Author: User

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!

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.