| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:我的表单验证为什么会出错
只看楼主 加入收藏
大猪小猪
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-4-18
收藏
 问题点数:0 回复次数:2 
我的表单验证为什么会出错
我的这个表单每次提交都不执行为什么呢,帮忙看看吧各位


<script language=javascript>
 function CheckForm(the)
{
if(the.form1.name.value.length==""){
      alert("输入框不能为空!");
      the.form1.name.focus();
      return false;
     }
//判断昵称不能为以下特殊符号
    tChk = /^[^ \s~!@#$%\^\&\*\(\)_\+|\-\=\/\?:;'"\[\{\]\}`\.>,<\\]+$/;
    if(!tChk.exec(the.form1.name.value)){
        alert("请输入正确的姓名!\n\n姓名必须在1-10位之间,且不得含有特殊符号!");
        the.form1.name.focus();
        return false;
    }
if(if(the.form1.name.value.length>10){
        alert("姓名不能大于5个汉字!");
        the.form1.name.focus();
        return false;
    }
     if(the.form1.ID.value.length==0){
      alert("员工ID号不能为空!");
      the.form1.ID.focus();
      return false;
     }
if(isNaN(the.form1.ID.value))
         {
             alert("员工ID号只能是数字");
            
             return  false;        
         }
if(the.form1.password.value==""){
        alert("员工密码不能为空!");
        the.form1.ID.focus();
        return false;
    }

   }
if(the.form1.password.value.length<6){
      alert("员工密码过于简单!");
      the.form1.password.focus();
      return false;
     }
     if(the.form1.sex.value.length==""){
      alert("请选择员工的性别!");
      the.form1.password.focus();
      return false;
     }
      if (the.all.form1.saraly.value.search(re1) != -1) {
    } else {
    alert("工资必须是数字.")
    the.form1.tel.focus();
    return false;
    }
     if (the.all.form1.age.value.search(re1) != -1) {
    } else {
    alert("年龄必须是数字.")
    the.form1.age.focus();
    return false;
    }
    if(dthe.form1.telephone.value==""){
        alert("联系电话不能为空!");
        the.form1.telephone.focus();
        return false;
    }
     if (the.all.form1.telephone.value.search(re1) != -1) {
    } else {
    alert("电话必须是数字.")
    the.form1.telephone.focus();
    return false;
    }
}
</script>

<div align="center">
  <p align="center" class="style1"> 添加新员工
</p>
<form  action="?action=addnew.asp" name="form1" method="POST" onsubmit="return CheckForm(this);">
  <table width="508" height="404" border="1">
    <tr>
      <td width="102"><div align="center"><span class="style2">姓名:</span></div></td>
      <td width="390"><input type="text" name="name">*必填字段</td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">ID:</span></div></td>
      <td><input type="text" name="ID">*必填字段</td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">密码</span>:</div></td>
      <td><input type="text" name="password">
      *必填字段</td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">性别</span>:</div></td>
      <td><input type="radio" name="sex" value="male">
        
        <input type="radio" name="sex" value="female">
        女 *必选其一</td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">职位</span>:</div></td>
      <td><input type="text" name="position"></td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">工资</span>:</div></td>
      <td><input type="text" name="saraly"></td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">年龄</span>:</div></td>
      <td><input type="text" name="age"></td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">入职时间</span>:</div></td>
      <td><input type="text" name="beginworktime"></td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">联系电话</span>:</div></td>
      <td><input type="text" name="telephone">   *必填字段
      </td>
    </tr>
    <tr>
      <td><div align="center"><span class="style2">家庭住址</span>:</div></td>
      <td><input type="text" name="address"></td>
    </tr>
  </table>
  
  <p class="style1">   </p>
  <p>
    <input name="Submit" type="submit" class="button" value="添加" >
    <input name="Submit" type="reset" class="button" value="重新填写">
  </form>

[[it] 本帖最后由 大猪小猪 于 2008-4-17 16:32 编辑 [/it]]
搜索更多相关主题的帖子: 表单 验证 
2008-04-17 14:56
tianyu123
Rank: 1
等 级:新手上路
威 望:2
帖 子:576
专家分:0
注 册:2007-8-26
收藏
得分:0 
加上红色部分(在下面)
<script language=javascript>
function CheckForm(the)
{
if(the.form1.name.value.length==""){
      alert("输入框不能为空!");
      the.form1.name.focus();
      return false;
     }
//判断昵称不能为以下特殊符号
    tChk = /^[^ \s~!@#$%\^\&\*\(\)_\+|\-\=\/\?:;'"\[\{\]\}`\.>,<\\]+$/;
    if(!tChk.exec(the.form1.name.value)){
        alert("请输入正确的姓名!\n\n姓名必须在1-10位之间,且不得含有特殊符号!");
        the.form1.name.focus();
        return false;
    }
if(if(the.form1.name.value.length>10){
        alert("姓名不能大于5个汉字!");
        the.form1.name.focus();
        return false;
    }
     if(the.form1.ID.value.length==0){
      alert("员工ID号不能为空!");
      the.form1.ID.focus();
      return false;
     }
if(isNaN(the.form1.ID.value))
         {
             alert("员工ID号只能是数字");
            
             return  false;        
         }
if(the.form1.password.value==""){
        alert("员工密码不能为空!");
        the.form1.ID.focus();
        return false;
    }

   }
if(the.form1.password.value.length<6){
      alert("员工密码过于简单!");
      the.form1.password.focus();
      return false;
     }
     if(the.form1.sex.value.length==""){
      alert("请选择员工的性别!");
      the.form1.password.focus();
      return false;
     }
      if (the.all.form1.saraly.value.search(re1) != -1) {
    } else {
    alert("工资必须是数字.")
    the.form1.tel.focus();
    return false;
    }
     if (the.all.form1.age.value.search(re1) != -1) {
    } else {
    alert("年龄必须是数字.")
    the.form1.age.focus();
    return false;
    }
    if(dthe.form1.telephone.value==""){
        alert("联系电话不能为空!");
        the.form1.telephone.focus();
        return false;
    }
     if (the.all.form1.telephone.value.search(re1) != -1) {
    } else {
    alert("电话必须是数字.")
    the.form1.telephone.focus();
    return false;
    }
return true;
}
</script>

改变一切,须从改变观念开始!
2008-04-17 17:39
大猪小猪
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-4-18
收藏
得分:0 
谢谢
谢谢你的修改,只是还是不正确,我已经做了修改了
2008-04-18 19:55
快速回复:我的表单验证为什么会出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021412 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved