JS Verification Code

Source: Internet
Author: User

<! DOCTYPE html><meta charset= "Utf-8" ><title>idCode</title><style>. code{font-family:arial; Font-style:italic; color:red; border:0; padding:2px 3px; letter-spacing:3px; Font-weight:bold;Background:yellow;opacity:0.8;        }  #checkCode {width:60px;Text-align:center;        }</style> <form action= "#" ><input type= "text" id= "Invalue" ><input type= "text" readonly= "readonly" id= "Checkcode" class= "code" ><br><br><input id= "btn" type= "button" value= "OK" ></form><script>window.onload = function () {Createcode ();var checkcode = document.getelementbyid_x_x_x ("Checkcode");var btn = document.getelementbyid_x_x_x ("btn");Checkcode.onclick = function () {Createcode ();    }Btn.onclick = function () {validate ();    }}var code;//in global definition verification codefunction Createcode () {code = "";//code store Stringvar codelength = length of 4;//verification codevar Selectchar = [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 ', ' 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 candidate components of the verification code, of course, can also be used in Chinesevar getrandomcolor = function () {return ' # ' + (Math.random () *0xffffff<<0). ToString (+);}//randomly generated background colorFor (var i=0; i < codelength; i + +)        {  var charIndex = Math.floor (Math.random () *62);//alert (CharIndex); code + = Selectchar[charindex];         }  //alert (code); if (checkcode)        {  CheckCode.style.background = Getrandomcolor ();checkcode.value = code;         }      }   function Validate () {var inputcode = document. getElementById ("Invalue"). Value; if (inputcode.length<=0)        {  alert ("Please enter the verification code!)  ");         }  Else if (Inputcode.touppercase ()!=code.touppercase ())        {  alert ("Verification code input Error!  "); Createcode ();//Refresh Verification Code        }  Else        {  alert ("Enter correctly, verify success");         }      }  </script></body>

JS Verification Code

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.