简单的注册表验证码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function registerForm() {
            var userName=document.getElementById("userName").value;
            var pwd=document.getElementById("pwd").value;
            var repwd=document.getElementById("repwd").value;
            var address=document.getElementById("address").value;
            var code=document.getElementById("code").value;
            var matchResult=true;
            if(userName==''||pwd==''||repwd==''||address==''){
                alert("不能有空值");
                matchResult=false;
            }else if(userName.length<6 || userName.length>20){
                alert("用户名应在6个或20个内");
                matchResult=false;
            } else if(pwd!=repwd){
                alert("密码与重复密码输入不同");
                matchResult=false;
            }else if(pwd.length<6 || pwd.length>20){
                alert("密码应在6个或20个内");
                matchResult=false;
            }if(matchResult==true){
                if(code==''){
                    alert('请输入验证码');
                    matchResult=false;
                }else if(code.toUpperCase() != checkCode.toUpperCase()){
                    alert('验证码输入错误');
                    createCode();
                    matchResult=false;
                }
            }
            return matchResult;
        }

        var checkCode;
        function createCode() {
            var code=document.getElementById("checkCode"),
                    codeLength=6,
                    codeArray=[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','s','r','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','S','R','T','U','V','W','X','Y','Z'];
            checkCode='';
            for(var i=0;i<codeLength;i++){
                var codeRandom=Math.floor(Math.random()*62);
                checkCode +=codeArray[codeRandom];
            }
            if(checkCode){
                code.innerHTML=checkCode;
            }
        }
    </script>
</head>
<body οnlοad="createCode()">
<form action="login.html" method="post" οnsubmit="return registerForm()">
    <h1>注册</h1>
    <p>用户名:<input type="text" id="userName"><small>用户名应在6个或20个内</small></p>
    <p>密码:<input type="password" id="pwd"><small>密码应在6个或20个内</small></p>
    <p>重复密码:<input type="password" id="repwd"></p>
    <p>邮箱:<input id="address" type="email"></p>
    <p><span id="checkCode" οnclick="createCode()"></span><span  οnclick="createCode()">看不出清</span></p>
    <p>验证码:<input type="text" id="code"> 请输入验证码</p>
    <input type="submit" value="submit">
</form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值