javascript--Analog Verification Code

Source: Internet
Author: User
Tags define function

1<!doctype html>234<meta charset= "UTF-8" >5<title>Document</title>6<script>7 //randomly generated verification code:8   //STEP1: Put all the alternate characters in the array9   varchars=[];Ten    for(vari=48; Onei<=57; AChars.push (String.fromCharCode (i)), i++); -    for(varI=65; -I<=90; theChars.push (String.fromCharCode (i)), i++); -    for(vari=97; -i<=122; -Chars.push (String.fromCharCode (i)), i++); +   //Console.log (String (chars)); -   //Step2: Define function GetCode, randomly select 4-position characters +   functionGetCode () { A     //I start from 1, to <=4 end, while declaring the empty string code at      for(varI=1,code= ""; i<=4;i++){ -       //randomly pick a location from 0~chars's length-1 and save it in R -       varR=math.floor (Math.random () *(Chars.length)); -       //stitching the characters of R position in chars to code -code+=Chars[r]; -     } in     returnCode; -   } to Console.log (GetCode ()); +   //Step3: Repeatedly ask the user to enter the verification code: -   //declares the variable code, initialized to a verification code returned by GetCode () the   varCode=GetCode (); *   //repeatedly ask the user to enter the verification Code (code) into lowercase results, not equal to the result of code to lowercase letters $    while(Prompt ("Enter the verification code (" +code+ ")"). toLowerCase ()Panax Notoginseng!=code.tolowercase ()) { -Alert ("The verification code is wrong! ")//hint: wrong CAPTCHA!  the     //call GetCode () to get a new captcha saved in code +Code=GetCode (); A}//(traversal end) thedocument.write ("

); +</script> - $<body> $ -</body> -

javascript--Analog Verification Code

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.