js验证码(数字,字母组合)


function getyzm() {
code = "";
var codeLength = 4; //验证码的长度   
var checkCode = document.getElementById("show_yzm");
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', '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'); //所有候选组成验证码的字符,当然也可以用中文的     
for(var i = 0; i < codeLength; i++) {
var charIndex = Math.floor(Math.random() * 52); //Math.random得到0-36中随机的一个数,floor取整数部分
code += selectChar[charIndex];
}
//       alert(code);   
if(checkCode) {
checkCode.value = code;
}
}
function validate() {
var inputCode = document.getElementById("yzm").value;
if(inputCode.length <= 0) {
alert("请输入验证码!");
} else if(inputCode.toLowerCase() != code.toLowerCase()) {
alert("验证码输入错误!");
createCode(); //刷新验证码   
} else {
alert("验证成功");
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM