JavaScript validation code Generation code recommendation Learning _javascript Skills

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title>javascript Verification Code Implementation Code _ cloud-dwelling community test </ title> <style type= "Text/css" > Code {} {Background-image:url (code.jpg); font-family:arial; Font-style:italic; color:red; border:0; PADDING:2PX 3px; letter-spacing:3px; Font-weight:bolder; }. Unchanged {} {border:0; } </style> <script language= "javascript" type= "Text/javascript" > 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 that make up the verification code, of course, can also be in Chinese for (Var i=0;i<codelength;i++) {var charIndex = Ma Th.floor (Math.random () *36); Code +=selectchar[charindex]; } if (Checkcode) {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!") "); else if (Inputcode!= code) {alert ("Validation code input Error!) "); Createcode ()//Refresh Verification code} else {alert ("^-^ OK"); } </script> </pead> <body onload= "Createcode ()" > <form action= "#" > <input type= "Text" Id= "input1"/> <input type= "text" onclick= "Createcode ()" readonly= "readonly" id= "Checkcode" class= "unchanged"/& Gt <input id= "Button1" onclick= Validate (); "type=" button "value=" OK "/> </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.