3710人加入学习
(6人评价)
Web前端第三季(JavaScript)

制作完成于2018年6月14日

价格 免费
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>注册功能(表单校验)</title>
    <script type="text/javascript">
        function check(){
            // alert("check");
            var username = document.getElementById("username");
            
            // console.log(username);
            // console.log(username.value);
            var length = username.value.length;
            if(length<3 || length>6){
                alert("用户名长度必须是3-6位");
            }
            //正则表达式在线测试 https://c.runoob.com/front-end/854
            var email = document.getElementById("email").value;
            var p = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            if(p.test(email) == false){
                alert("邮箱格式不正确!");
            }
            return false;
        }
    </script>
</head>
<body>
    <form action="register.jsp" onsubmit="return check()">
        <table border="1" width="500px" height="500px">
            <tr>
                <td colspan="2" align="center">注册</td>
            </tr>
            <tr>
                <td align="right">用户名:</td><td align="left"><input type="text" id="username" /></td>
            </tr>
            <tr>
                <td align="right">邮箱:</td><td><input type="text" id="email"/></td>
            </tr>
            <tr>
                <td align="right">密码:</td><td><input type="password" /></td>
            </tr>
            <tr>
                <td align="right">重复密码:</td><td><input type="password" /></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="注册"/></td>
            </tr>
        </table>
    </form>
</body>
</html>

校验要求
用户名长度必须位于3到6位之间
密码必须是6到10为之间
密码和重复密码必须一样
邮箱格式 xxx@xxx    第二部分是域名结尾.com .org .cn .net等

[展开全文]

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(60)