81,092
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>My JSP 'query.jsp' starting page</title>
<script type="text/javascript">
function isPasswd(s){
var patrn=/^(\w){4,12}$/;
if (!patrn.exec(s)) return false;
return true;
}
function ResetBt(){
document.all['loginForm'].reset();
document.getElementById("account").focus();
return false;
}
function CheckForm(){
if(document.getElementById("account").value.length==0){
alert("对不起!您输入的账号不能为空!");
document.getElementById("account").focus();
return false;
}
if((document.getElementById("account").value.length>16)||(document.getElementById("account").value.length<5)){
alert("对不起!帐号的长度必须为5到16个有效字符!");
document.getElementById("account").focus();
return false;
}
if(isPasswd(document.getElementById("account").value)==false)
{
alert("对不起!帐号只能输入5-16个字母、数字、下划线!");
document.getElementById("account").focus();
return false;
}
if(document.getElementById("pwd").value.length==0){
alert("对不起!密码不能为空!");
document.getElementById("pwd").focus();
return false;
}
if((document.getElementById("pwd").value.length>16)||(document.getElementById("pwd").value.length<5)){
alert("对不起!密码的长度必须为5到16个有效字符!");
document.getElementById("pwd").focus();
return false;
}
if(isPasswd(document.getElementById("pwd").value)==false)
{
alert("对不起!密码只能输入5-16个字母、数字、下划线!");
document.getElementById("pwd").value="";
document.getElementById("pwd").focus();
return false;
}
else{
document.getElementById('loginForm').submit();
return true;
}
}
</script>
</head>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"> </script>
<body>
<form action="" method="post">
<p>username :
<input name="account" type="text" >
</p>
<p>password :
<label>
<input type="password" name="pwd">
</label>
</p>
<p>
<label>
城市 :
<select name="select">
<option selected>city</option>
<option>北京</option>
<option>上海</option>
<option>武汉</option>
<option>杭州</option>
<option>成都</option>
</select>
</label>
</p>
<p>
开始时间:<input type="text" class="inputText" name="starttime" id="starttime" onClick="new WdatePicker(this,false)"/>
至:<input type="text" class="inputText" name="starttime2" id="starttime2" onClick="new WdatePicker(this,false)"/>
<p>
<input type="submit" name="Submit" value="提交" onClick="return CheckForm();">
<input type="reset" name="Submit2" value="重置" onClick="return ResetBT();">
</p>
</form>
</body>
</html>
首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
欢迎您:feng8008 | 退出 | 登录 注册 帮助
我的帖子我参与的帖子我的空间我的网摘
CSDNCSDN社区JavaWeb 开发将帖子提前 放进我的网摘 推荐给好友 我要提问 帖子加分 生成帖子 置顶 推荐(加精) 取消推荐(加精) 锁定帖子 移动帖子 取消引用结贴去... 管理菜单 页面风格切换标准风格老版本论坛 请问这个验证怎么写?
加为好友
发送私信
在线聊天
whlusha720
lusha
等级:
发表于:2008-09-02 10:49:55 楼主
想验证
1 . 验证城市 当城市的没有被选择(值为默认的city 或者为空)的时候 在这一行后面显示错误提示
2 . 验证时间 当开始时间 和 结束时间为空 或者 开始时间大于结束时间的时候 在这一行后面显示错误提示
这是我的JSP代码
query.jsp
Java code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>My JSP 'query.jsp' starting page</title>
<script type="text/javascript">
function isPasswd(s){
var patrn=/^(\w){4,12}$/;
if (!patrn.exec(s)) return false;
return true;
}
function ResetBt(){
document.all['loginForm'].reset();
document.getElementById("account").focus();
return false;
}
function CheckForm(){
if(document.getElementById("account").value.length==0){
alert("对不起!您输入的账号不能为空!");
document.getElementById("account").focus();
return false;
}
if((document.getElementById("account").value.length>16)||(document.getElementById("account").value.length<5)){
alert("对不起!帐号的长度必须为5到16个有效字符!");
document.getElementById("account").focus();
return false;
}
if(isPasswd(document.getElementById("account").value)==false)
{
alert("对不起!帐号只能输入5-16个字母、数字、下划线!");
document.getElementById("account").focus();
return false;
}
if(document.getElementById("pwd").value.length==0){
alert("对不起!密码不能为空!");
document.getElementById("pwd").focus();
return false;
}
if((document.getElementById("pwd").value.length>16)||(document.getElementById("pwd").value.length<5)){
alert("对不起!密码的长度必须为5到16个有效字符!");
document.getElementById("pwd").focus();
return false;
}
if(isPasswd(document.getElementById("pwd").value)==false)
{
alert("对不起!密码只能输入5-16个字母、数字、下划线!");
document.getElementById("pwd").value="";
document.getElementById("pwd").focus();
return false;
}
else{
document.getElementById('loginForm').submit();
return true;
}
}
function checkUser(){
if(document.getElementById("account").value.length==0){
document.getElementById("user").innerHTML="对不起!您输入的账号不能为空!");";
}
}
</script>
</head>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"> </script>
<body>
<form action="" method="post">
<p>username :
<input name="account" type="text" onblur="checkUser()"><span id="user"></span>
</p>
<p>password :
<label>
<input type="password" name="pwd">
</label>
</p>
<p>
<label>
城市 :
<select name="select">
<option selected>city</option>
<option>北京</option>
<option>上海</option>
<option>武汉</option>
<option>杭州</option>
<option>成都</option>
</select>
</label>
</p>
<p>
开始时间:<input type="text" class="inputText" name="starttime" id="starttime" onClick="new WdatePicker(this,false)"/>
至:<input type="text" class="inputText" name="starttime2" id="starttime2" onClick="new WdatePicker(this,false)"/>
<p>
<input type="submit" name="Submit" value="提交" onClick="return CheckForm();">
<input type="reset" name="Submit2" value="重置" onClick="return ResetBT();">
</p>
</form>
</body>
</html>