Realization of Digital English Verification Code Based on javascript

  • 2021-07-13 04:30:16
  • OfStack

In this paper, we share the specific code of js to realize digital English verification code for your reference. The specific contents are as follows


<html>
<head>
<style type="text/css">
.code{
background-image:url(111.jpg);
font-family:Arial, Song Style ;
font-style:italic;
color:green;
border:0;
padding:2px 3px;
letter-spacing:3px;
font-weight:bolder;
}
.unchanged {
border:0;
}
</style>
<script language="javascript" type="text/javascript">
var code ; // In the global   Define verification code 
function createCode(){
code = new Array();
var codeLength = 4;// Length of verification code 
var checkCode = document.getElementById("checkCode");
checkCode.value = "";

var selectChar = new Array(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();
}
checkCode.value = code;
}

function validate () {
var inputCode = document.getElementById("input1").value.toUpperCase();

if(inputCode.length <=0) {
alert(" Please enter the verification code! ");
return false;
}
else if(inputCode != code ){
alert(" Wrong input of verification code! ");
createCode();
return false;
}
else {
alert(" Success! ");
return true;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body onLoad="createCode();">

<input type="text" id="input1" />
<input type="button" id="checkCode" class="code" style="width:60px" onClick="createCode()" /> <a href="#" onClick="createCode()"> Can't see clearly </a>
<input id="Button1" onClick="validate();" type="button" value=" Determine " />
<script></script>
</body>
</html>

Related articles: