注册页面表单验证

来源:互联网 发布:ug软件安装教程 编辑:程序博客网 时间:2024/05/16 07:37

这里只写一个实例。


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>留言板注册</title>
<script type="text/javascript">  
function check(){
    var username = document.form1.username.value;
    var password = document.form1.password.value;
    var password2 = document.form1.password2.value;
    if(username==""||password=="")
        {
            alert("用户名密码不能为空!");
            return false;
        }else if(password.length<6){
            alert("密码不能少于6位!");
            return false;
        }
        else if(password!=password2){
            alert("两次密码输入不一致!");
            return false;
        }
    }

</script>
</head>

<body>
    <center>
        <img src="<%=request.getContextPath() %>/jsp/images/logo.png" alt="balabala"/>
        <h3>留言板</h3>
        </br>
    </center>
    <center>
        <h2>用户注册</h2>
    
        <form action="../user/register.do" method="post" name="form1" onsubmit="return check(this)">
             用户名&nbsp;&nbsp;&nbsp;:
            <input onkeyup="value=value.replace(/[\W]/g,'') "   
            onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" type="text" name="username" maxlength=10 style="width: 150"><font color=red>*</font></br>
            密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="password" maxlength=10 style="width: 150"><font color=red>*</font></br>
            确认密码:<input type="password" name="password2" maxlength=10 style="width: 150"><font color=red>*</font></br></br>
            
            <input type="submit" value="注册"> <input type="reset" value="取消"></br></br>
        <a href="../user/logout.do">欢迎登录</a>     
        </form><br>
        
        <font color=red>${model.error}</font>
    </center>
</body>

0 0
原创粉丝点击