正则表达式(表单验证blur)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0 auto;
        }
        button{
            display: block;
            margin: 0 auto;
        }
        input{
            background-color: #c7edcc;
        }
        /*td{*/
            /*border: 1px solid #000;*/
        /*}*/
        img{
            width: 20px;
            height: 20px;
        }
        table,td{
            /*边框合并*/
            border-collapse: collapse;
            border: 1px solid #000;
        }

    </style>
    <script src="jquery-1.11.1.min.js"></script>
    <script>
        $(function () {
            $("tr td:first-child").css("background"," #c7edcc");
            $("span").hide();
            var x=0;
            //邮箱
            var email = $(".email").val();
            $(".email").blur(function () {
                var ereg = /.+@.+\.[a-zA-Z]{2,4}$/;
                  if(ereg.test($(".email").val())){
                      $(this).parents("td").next().children("span:last").hide();
                      $(this).parents("td").next().children("span:first").show();
                      x++;
                  }else{
                      $(this).parents("td").next().children("span:first").hide();
                      $(this).parents("td").next().children("span:last").show();
                      console.log(1);
                  }
            });
            //昵称
            var name = $(".name").val();
            $(".name").blur(function () {
                 if($(".name").val().length>4){
                     $(this).parents("td").next().children("span:last").hide();
                     $(this).parents("td").next().children("span:first").show();
                     x++;
                  }else{
                     $(this).parents("td").next().children("span:first").hide();
                     $(this).parents("td").next().children("span:last").show();
                  }
            });
            //密码
            var pwd = $(".pwd").val();
            $(".pwd").blur(function () {
                  if( $(".pwd").val().length>6){
                      $(this).parents("td").next().children("span:last").hide();
                      $(this).parents("td").next().children("span:first").show();
                      x++;
                  }else{
                      $(this).parents("td").next().children("span:first").hide();
                      $(this).parents("td").next().children("span:last").show();
                  }
            });
//            再一次输入
            var rpwd = $(".rpwd").val();
                $(".rpwd").blur(function () {
                  if($(".rpwd").val()!=$(".pwd").val()){
                      $(this).parents("td").next().children("span:first").hide();
                      $(this).parents("td").next().children("span:last").show();
                        x++;
                  }else{
                      $(this).parents("td").next().children("span:last").hide();
                      $(this).parents("td").next().children("span:first").show();

                  }
            });
//            注册按钮
//            $(".zhuce").click(function () {
//                if($(".email").val()!=""&&$(".name").val()!=""&&$(".pwd").val()!=""&&$(".epwd").val()!=""&&$(".rpwd").val()==$(".pwd").val()){
//                    alert("符合要求");
//                }else{
//                    alert("不符合要求");
//                }
//            })
            $(".zhuce").click(function () {
                if(x==4){
                    alert("符合要求");
                }else{
                    alert("不符合要求");
                }
            })
        })
    </script>
</head>
<body>

    <!--行内实线<table cellspacing="0" cellpadding="0.1" border="1px">-->
    <table>
        <tr>
            <td>请填写您的Email地址:</td>
            <td><input type="text" class="email"></td>
            <td>请填写有效的Email地址,在下一步中您将用此邮箱接收验证邮件。<br>
                <span><img src="img/dui.gif">用户名可用</span><span><img src="img/cuo.gif">用户名不可用</span></td>
        </tr>
        <tr>
            <td>请填写您在当当网的昵称:</td>
            <td><input type="text" class="name"></td>
            <td>您的昵称可以由小写英文字母,中文、数组组合才能,长度4-20个字符,一个汉字为两个字符<br>
                <span><img src="img/dui.gif">昵称可用</span><span><img src="img/cuo.gif">昵称不可用</span></td>
        </tr>
        <tr>
            <td>设置密码:</td>
            <td><input type="text" class="pwd"></td>
            <td>您的密码可由大小写英文字母、数字组成,长度6-20位<br>
                <span><img src="img/dui.gif">密码可用</span><span><img src="img/cuo.gif">密码不可用</span></td>
        </tr>
        <tr>
            <td>再次输入密码:</td>
            <td><input type="text" class="rpwd"></td>
            <td>
                <span><img src="img/dui.gif">密码一致</span><span><img src="img/cuo.gif">密码不一致</span></td>
        </tr>
    </table>
<button class="zhuce">注册</button>
</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值