js 表单检验 dom bom

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>window对象</title>
    <style>
        .t-left {
            /*文字靠左边*/
            text-align: left;

        }

        input[type="text"], input[type="password"], input[type="email"]
         {
            padding-top: 6px;
            padding-bottom: 6px;
            padding-left: 10px;
            padding-right: 10px;
            border-radius: 4px; /*圆角*/
            border: gray solid 1px;
            margin-left: 30px; /*指定左边距,调节左边距的距离*/
        }

        body {

            background-image: url("timg.jpg");

        }

        * {
            padding: 0px;
            margin: 0px;
            box-sizing: border-box;
        }
        .mid {
            font-size: 15px;
            float: left;
            width: 47%;
            margin-top: 280px;
        }
        body > div {
            width: 850px;
            height: 400px;
            background-color: white;
            border: gray solid 8px;
            margin: 60px auto;
        }

        .left {
            float: left;
            width: 25%;
            margin-left: 20px;
            margin-top: 20px;
        }

        .first {
            font-size: 20px;
            color: orange;

        }

        .left p:last-child {
            font-size: 20px;
            color: gray;
        }

        .right {
            float: right;
            width: 25%;
        }

        .right p {
            font-size: 15px;
            padding: 10px 10px 0px 0px;
            float: right;
            margin-left: 30px;
            color: gray
        }



    </style>
    <script>

        function shoeTips(spanId, tips) {

            var span = document.getElementById(spanId);

            span.innerHTML = tips;

        }

        /**

         * 校验用户名

         */

        function hint() {

            var value = document.getElementById("value").value;

            var hint = document.getElementById("hint");

            if(value.length < 6) {

                hint.innerHTML = "用户名太短";

                return false;

            } else {

                hint.innerHTML = "用户名合格";

                return true;

            }

        }



        function hint_hide() {

            var hint = document.getElementById("hint");

            hint.innerHTML = "";

        }

        /**

         * 校验密码

         */



        function checkPass() {

            var value = document.getElementById("pass_value").value;

            var hint = document.getElementById("pass_hint");

            if(value.length < 6) {

                hint.innerHTML = "密码太短";

                return false;

            } else {

                hint.innerHTML = "密码格式合格";

                return true;

            }

        }



        function pass_hide() {

            var hint = document.getElementById("pass_hint");

            hint.innerHTML = "";

        }

        /***

         * 确认密码的校验

         */

        function checkPassPass() {

            var papavalue = document.getElementById("passpass_value").value;

            var value = document.getElementById("pass_value").value;

            var papahint = document.getElementById("passpass_hint");

            if(papavalue != value) {

                papahint.innerHTML = "两次密码不一致";

                return false;

            } else {

                papahint.innerHTML = "合格";

                return true;

            }

        }



        function passpass_hide() {

            var papahint = document.getElementById("passpass_hint");

            papahint.innerHTML = "";

        }

        /**

         * 校验邮箱

         */

            function checkEmail(strEmail)

            {

                var emailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])$/;

                if ( emailReg.test(strEmail) ) {

                    return true;

                }

            else {

//      alert("您输入的Email地址格式不正确!");

                return false;

            }

        };

        function emailCheck() {

            var emailValue = document.getElementById("email").value;

            var email_hint = document.getElementById("email_hint");

            var flag = checkEmail(emailValue);

            if(flag) {

                email_hint.innerHTML = "邮箱格式正确";

                return true;

            } else {

                email_hint.innerHTML = "邮箱格式错误";

                return false;

            }

        }



        function emailHide() {

            var email_hint = document.getElementById("email_hint");

            email_hint.innerHTML = "";

        }

        /**

         * 校验手机号

         */

        function checkMobile( strMobile )

        {	//13588888888

            var regu = /^[1][345678][0-9]{9}$/;


            if (regu.test(strMobile)) {

                return true;

            }

            else {

                return false;

            }

        };

        function phoneCheck() {

            var phone = document.getElementById("phone").value;

            var phone_hint = document.getElementById("phone_hint");

            var flag = checkMobile(phone);

            if(flag) {

                phone_hint.innerHTML = "手机号格式正确";

                return true;

            } else {

                phone_hint.innerHTML = "手机号格式错误";

                return false;

            }

        }



        function phoneHide() {

            var phone_hint = document.getElementById("phone_hint");

            phone_hint.innerHTML = "";

        }



        function checkForm() {

            var flag = emailCheck() && checkPass() && checkPassPass() && hint() && phoneCheck();

            return flag;


        }


    </script>
</head>
<body>



<form action="#" onsubmit="return checkForm()">
    <div class="left">
        <p class="first">新用户注册</p>
        <p class="third">user register</p>
    </div>
    <table align="center" bgcolor="blue" width="550" border="1">

        <div class="mid">
    <tr>
        <div class="text">

            <td class="t-left"><p>用户名</p>

            </td>
            <td class="t-right"><input id="value" onfocus="shoeTips('hint','用户名长度不能小于六')" onblur="hint_hide()" onkeyup="hint()" type="text" Name="Userame" placeholder="用户名" />

            <span id="hint"></span>
            </td>

        </div>
     </tr>
        <tr>

        <div class="text">
            <td class="t-left"><p>密码</p>
            </td>
            <td class="t-right"> <input id="pass_value" onfocus="shoeTips('pass_hint','密码长度不能小于六')" onblur="pass_hide()" onkeyup="checkPass()" type="password" name="password" placeholder="密码" />


            <span id="pass_hint"></span>
            </td>

        </div>
        </tr>

        <tr>
        <div class="text">

            <td class="t-left"><p>确认密码</p></td>

            <td class="t-right"><input id="passpass_value" onfocus="shoeTips('passpass_hint','两次密码要一致')" onblur="passpass_hide()" onkeyup="checkPassPass()" type="password" name="password" placeholder="确认密码" />

            <span id="passpass_hint"></span>
            </td>

        </div>
        </tr>

        <tr>
        <div class="text">

            <<td class="t-left"><p>邮箱</p></td>

            <td class="t-right"><input id="email" onfocus="shoeTips('email_hint','邮箱格式要正确')" onblur="emailHide()" onkeyup="emailCheck()" type="email" name="email" placeholder="邮箱" />
            <span id="email_hint"></span></td>

        </div>
        </tr>

        <tr>
        <div class="text">

            <td class="t-left"><p>手机号</p></td>

            <td class="t-right"><input id="phone" type="text" onfocus="shoeTips('phone_hint','格式为十一位数字的手机号')" onblur="phoneHide()" onkeyup="phoneCheck()" Name="Phone" placeholder="手机号">

            <span id="phone_hint"></span>
        </td>
        </div>
        </tr>



        <tr>
        <div class="submit" >
        <td colspan="2" align="center"> <input type="submit" name="登录" value="登录"></td>
    </div>
        </tr>

        <div class="right">
            <p>已有账号?<a href="#">立即登陆</a></p>
        </div>

        </div>
    </table>
</form>

</body>
</html>

还是丑  太麻烦了 不像修改了
检验 只演示一个了
****

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值