当前位置:文档之家› jsp写的注册页面用javascript作有效性验证

jsp写的注册页面用javascript作有效性验证

<%@ page contentType="text/html; charset=gb2312" language="java" import="er" errorPage="" %><jsp:useBean id="user" scope="page" class="er"/><%//权限默认不是超级管理员boolean isAdmin = false ;String actionStr = "";if (session.getAttribute("user") != null){user = (User)session.getAttribute("user");//取出权限if (user.getUPopedom() ==0)isAdmin = true ;}String qFile = request.getRequestURI();System.out.println(qFile);//说明是超级管理员,并在后台添加用户if ("/admin/default.jsp".equals(qFile)){actionStr = "../" ;}%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>会员注册</title><SCRIPT language=JavaScript>function checkuserinfo(){if(checkspace(erName.value)) {erName.focus();alert("对不起,请填写用户名!");return false;}if(checkspace(document.form1.password1.value) || document.form1.password1.value.length < 6 || document.form1.password1.value.length >20) {document.form1.password1.focus();alert("密码长度不能不能这空,在6位到20位之间,请重新输入!");return false;}if(document.form1.password1.value != document.form1.password2.value) {document.form1.password1.focus();document.form1.password1.value = '';document.form1.password2.value = '';alert("两次输入的密码不同,请重新输入!");return false;}if(document.form1.email.value.length!=0){if (document.form1.email.value.charAt(0)=="." ||document.form1.email.value.charAt(0)=="@"||document.form1.email.value.indexOf('@', 0) == -1 ||document.form1.email.value.indexOf('.', 0) == -1 ||stIndexOf("@")==document.form1.email.value.length-1 || stIndexOf(".")==document.form1.email.value.length-1) {alert("Email地址格式不正确!");document.form1.email.focus();return false;}}else{alert("Email不能为空!");document.form1.email.focus();return false;}}function checkspace(checkstr) {var str = '';for(i = 0; i < checkstr.length; i++) {str = str + ' ';}return (str == checkstr);}</SCRIPT><style type="text/css"><!--.STYLE1 {color: #FF0000;font-weight: bold;}.STYLE2 {color: #FF0000}.STYLE3 {font-size: 18px;font-weight: bold;}--></style></head><body style="font-size:12px"><form id="form1" name="form1" method="post" onsubmit="return checkuserinfo();" action="<%=actionStr%>reg"><p align="center"><br /><span class="STYLE3">用户注册</span></p><table width="582" height="302" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#BCACD2"><tr><td width="80" align="right">用户名:</td><td width="496" align="left"><input name="userName" type="text" id="userName" size="16" maxlength="16" /><span class="STYLE1">*</span>中文或者英文</td></tr><tr><td align="right">密码:</td><td align="left"><input name="password1" type="password" id="password1" size="16" maxlength="16" /><span class="STYLE1">* </span> 6~20位字母或者数字</td></tr><tr><td align="right">确认密码:</td><td align="left"><input name="password2" type="password" id="password2" size="16" maxlength="16" /><span class="STYLE1">*</span> 必须和上面输入的密码相同</td></tr><tr><td align="right">电子邮件:</td><td align="left"><input name="email" type="text" id="email" maxlength="20" /><span class="STYLE1">*</span> 找回密码和联系用</td></tr><td align="right">联系电话:</td><td align="left"><input name="tel" type="text" id="tel" size="20" maxlength="20" /></td></tr><tr><td align="right">联系地址:</td><td align="left"><input name="address" type="text" id="address" maxlength="50" /></td></tr><%if (isAdmin)//如果是管理员就显示出下拉列表{%><tr><td height="26" align="right">权限:</td><td align="left"><select name="popedom" id="popedom"><option value="0">超级管理员</option><option value="1">会员</option></select></td></tr><%}else//否则就插入一个蕴藏域{%><input type="hidden" name="popedom" value="1"><%}%><tr><td height="42" align="right">&nbsp;</td><td align="left"><span class="STYLE2">为了方便联系和管理请认真填写你的信息,带星号的必须填写</span></td></tr><tr><td height="40" colspan="2" align="center"><input type="submit" name="Submit" value="确认注册" onClick="return checkuserinfo();"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="Submit2" value="重新填写" /></td></tr></table></body> </html>。

相关主题