查看: 8151|回复: 4
打印 上一主题 下一主题

在PHP中提交给服务器时候之前客户端做检测"提交的数据是否符合要求"

[复制链接]
跳转到指定楼层
1#
发表于 2007-10-5 16:10:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
<form action="<?php $PHP_SELF?>" method="post" name="add" onSubmit="return check()">
      <table cellspacing=0 cellpadding=0 width="90%" align="center" border=0>
          <tbody>
               <tr bgcolor="EEEEEE"><td height="30" align="center" colspan="2">添加一网资讯分类</td></tr>
               <tr bgcolor="FFFFFF">                                                                <td height="30" align="center">资讯大类:</td>                                                <td>                                                                        <select name="bs">                                                                <?php                                                            
                                                                                $bs_sql = "select id,name from ".$sort_table." where flag=1";
                                                                                $db->execute($bs_sql);
                                                                                while($bs_info=$db->reader())
                                                                                {
                                                                                        $bs_id = $bs_info['id'];
                                                                                        $bs_name = $bs_info['name'];
                                                                                        echo "<option value=".$bs_id.">".$bs_name."</option>";       
                                                                                }

                                                                                ?>
                                                                                </select>
                                                                        </td>
                    </tr>
        <tr bgcolor="EEEEEE">
                                                                        <td height="30" width="20%" align="center">资讯子类:</td>
                                                                        <td height="30" width="80%" align="left"><input type="text" name="ssname" size="25"></td>
        </tr>
                     <tr bgcolor="FFFFFF">
                                                                        <td height="30" colspan="2" align="center"><input type="submit" name="add" value=" 添 加 " >  <input type="reset" name="rewrite" value=" 重 写 "></td>
        </tr>
                    <tr bgcolor="FFFFFF">
                                                                        <td height="7"></td>
        </tr>
         </tbody>
  </table>
</form>
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
2#
 楼主| 发表于 2007-10-5 16:11:08 | 只看该作者
台州网址导航
<form action="<?php $PHP_SELF?>" method="post" name="add">
<table cellspacing=0 cellpadding=0 width="90%" align="center" border=0>
                                                        <tbody>
                                                                <tr bgcolor="EEEEEE"><td height="30" align="center" colspan="2">添加一网资讯分类</td></tr>
                                                                <tr bgcolor="FFFFFF">
                                                                        <td height="30" align="center">资讯大类:</td>
                                                                        <td>
                                                                                <select name="bs">
                                                                                <?php
                                                                            
                                                                                $bs_sql = "select id,name from ".$sort_table." where flag=1";
                                                                                $db->execute($bs_sql);
                                                                                while($bs_info=$db->reader())
                                                                                {
                                                                                        $bs_id = $bs_info['id'];
                                                                                        $bs_name = $bs_info['name'];
                                                                                        echo "<option value=".$bs_id.">".$bs_name."</option>";       
                                                                                }

                                                                                ?>
                                                                                </select>
                                                                        </td>
                                                                </tr>
                                                                <tr bgcolor="EEEEEE">
                                                                        <td height="30" width="20%" align="center">资讯子类:</td>
                                                                        <td height="30" width="80%" align="left"><input type="text" name="ssname" size="25"></td>
                                                                </tr>
                                                                <tr bgcolor="FFFFFF">
                                                                        <td height="30" colspan="2" align="center"><input type="submit" name="add" value=" 添 加 " onclick="return check()">  <input type="reset" name="rewrite" value=" 重 写 "></td>
                                                                </tr>
                                                                <tr bgcolor="FFFFFF">
                                                                        <td height="7"></td>
                                                                </tr>
                                                        </tbody>
                                                </table>
                                          </form>
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
3#
 楼主| 发表于 2007-10-5 16:11:28 | 只看该作者
台州网址导航
check()函数具体检查用户提交的信息

<script language="javascript">

function isnumbercode(str){
        var digits="1234567890-/";
        var i=0;
        var strlen=str.length;
        while((i<strlen)){
                var char=str.charat(i);
                if(digits.indexof(char)==-1)return false;i++;
                                        }
        return true;
}

function check()
{
  if (document.frm.companyname.value.length==0){
      alert("单位名称不能为空!");
      mobj = eval("document.frm.companyname");
      mobj.focus()
      mobj.select()
          return false;
   }
   else if (document.frm.address.value.length==0){
      alert("单位地址不能为空!");
      mobj = eval("document.frm.address");
      mobj.focus()
      mobj.select()
          return false;
   }
  else if (document.frm.invest.value.length==0){
      alert("投资额不能为空!");
      mobj = eval("document.frm.invest");
      mobj.focus()
      mobj.select()
          return false;
   }
  else if(isNaN(document.frm.invest.value))  
  {
          alert("投资额只能为数字!");
      mobj = eval("document.frm.invest");
      mobj.focus()
      mobj.select()
          return false;
  }
  else if (document.frm.personnel.value.length==0){
      alert("员工人数不能为空!");
      mobj = eval("document.frm.personnel");
      mobj.focus()
      mobj.select()
          return false;
  }
   else if (isNaN(document.frm.personnel.value)){
      alert("员工人数只能为数字!");
      mobj = eval("document.frm.personnel");
      mobj.focus()
      mobj.select()
          return false;
  }
  else if (document.frm.codeornumber.value.length==0){
      alert("法人代码证书号或营业执照编号不能为空!");
      mobj = eval("document.frm.codeornumber");
      mobj.focus()
      mobj.select()
          return false;
  }
else if (document.frm.linkman.value.length==0){
      alert("联系人不能为空!");
      mobj = eval("document.frm.linkman");
      mobj.focus()
      mobj.select()
          return false;
   }
  else if (document.frm.linkmanjob.value.length==0){
      alert("联系人职位不能为空!");
      mobj = eval("document.frm.linkmanjob");
      mobj.focus()
      mobj.select()
          return false;
   }
   else if (document.frm.phone.value.length==0){
      alert("电话不能为空!");
      mobj = eval("document.frm.phone");
      mobj.focus()
      mobj.select()
          return false;
   }
   /* else if (isnumbercode(document.frm.phone.value)){
      alert("请输入如下形式的电话:0576-2441111!");
      mobj = eval("document.frm.phone");
      mobj.focus()
      mobj.select()
          return false;
   }*/

        else if (document.frm.phone.value.indexOf("-") == -1 ){
      alert("请输入电话号码格式如:0576-2572222");
      mobj = eval("document.frm.phone");
      mobj.focus()
      mobj.select()
          return false;
   }  
   else if (document.frm.fax.value.length==0){
      alert("传真不能为空!");
      mobj = eval("document.frm.fax");
      mobj.focus()
      mobj.select()
          return false;
   }
   /* else if (isnumbercode(document.frm.fax.value)){
      alert("请输入如下形式的传真:0576-2441111!");
      mobj = eval("document.frm.fax");
      mobj.focus()
      mobj.select()
          return false;
   }*/
        else if (document.frm.fax.value.indexOf("-") == -1 ){
      alert("请输入电话号码格式如:0576-2572222");
      mobj = eval("document.frm.fax");
      mobj.focus()
      mobj.select()
          return false;
   }
   else if (document.frm.email.value=="") {
        window.alert ("请输入您的E-mail地址 !")
        mobj = eval("document.frm.email");
        mobj.focus()
        mobj.select()
        return false
        }
        else if(document.frm.email.value.indexOf("@") == -1 || document.frm.email.value.indexOf(".") == -1){
        alert("请输入有效E-mail地址!");
        mobj = eval("document.frm.email");
        mobj.focus()
        mobj.select()
        return false;
        }
        else if (document.frm.introduction.value.length==0){
      alert("公司简介不能为空!");
      mobj = eval("document.frm.introduction");
      mobj.focus()
      mobj.select()
          return false;
   }   
        else if (document.frm.positionname.value.length==0){
      alert("职位名称不能为空!");
      mobj = eval("document.frm.positionname");
      mobj.focus()
      mobj.select()
          return false;
   }  
   else if (document.frm.jobaddress.value.length==0){
      alert("工作地点不能为空!");
      mobj = eval("document.frm.jobaddress");
      mobj.focus()
      mobj.select()
          return false;
   }  
   else if (document.frm.jobfunction.value.length==0){
      alert("工作职责不能为空!");
      mobj = eval("document.frm.jobfunction");
      mobj.focus()
      mobj.select()
          return false;
   }  
   else if (document.frm.positionrequre.value.length==0){
      alert("职位要求不能为空!");
      mobj = eval("document.frm.positionrequre");
      mobj.focus()
      mobj.select()
          return false;
   }  
   else if (document.frm.salary.value.length==0){
      alert("待遇不能为空!");
      mobj = eval("document.frm.salary");
      mobj.focus()
      mobj.select()
          return false;
   }
   else
   {
           return true;
   }
}
</script>
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
4#
 楼主| 发表于 2007-10-5 16:11:45 | 只看该作者
台州网址导航
check()函数具体检查用户提交的信息(继)

<script language="JavaScript">
function checkid(iden,year,month,day){

   if (iden.value.length==15) {
     
   
     if ((iden.value.lastIndexOf(month.value+day.value))==8) {
      
        return true;
     }
     return false;
   }
   if (iden.value.length==18) {
     
   
     if ((iden.value.indexOf(year.value+month.value+day.value))==6) {
      
        return true;
     }
     return false;
   }
   
   return false;
}


function isCharsInBag (s, bag)
{  
  var i;
  for (i = 0; i < s.length; i++)
  {   
      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) return false;
  }
  return true;
}
function isEmpty(s)
{  
        return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{  
  var whitespace = " \t\n\r";
  var i;
   for (i = 0; i < s.length; i++)
   {   
       var c = s.charAt(i);
       if (whitespace.indexOf(c) >= 0)
           {
                  return true;
           }
   }
   return false;
}
function isEmail (s,t)
{
    if (isEmpty(s))
        {
                window.alert("输入的E-mail地址不能为空,请输入!");        
        mobj = eval(t);
        mobj.focus();
        mobj.select();
                return false
        }
    if (isWhitespace(s))
        {
                window.alert("输入的E-mail地址中不能包含空格符,请重新输入!");        
        mobj = eval(t)
        mobj.focus()
        mobj.select()
                return false;
        }
   var i = 1;
   var len = s.length;

        if (len > 50)
        {
                window.alert("email地址长度不能超过50位!");
        mobj = eval(t)
        mobj.focus()
        mobj.select()
                return false;
        }
        
        pos1 = s.indexOf("@");
        pos2 = s.indexOf(".");
        pos3 = s.lastIndexOf("@");
        pos4 = s.lastIndexOf(".");
        if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))  
        {
                window.alert("请输入有效的E-mail地址!");
        mobj = eval(t)
        mobj.focus()
        mobj.select()
                return false;
        }
        else
        {
                if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
                  || ( pos1 != pos3 )  
                  || ( pos4 < pos3 ) )                  
                {
                        window.alert("请输入有效的E-mail地址!");
        mobj = eval(t)
  mobj.focus()
  mobj.select()
                        return false;
                }
        }

        if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
        {
                window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
        mobj = eval(t)
        mobj.focus()
                return false;
        }
                return true;
}
function isnumber(str){
        var digits="1234567890";
        var i=0;
        var strlen=str.length;
        while((i<strlen)){
                var char=str.charAt(i);
                if(digits.indexOf(char)==-1)return false;i++;
                                        }
        return true;
}
function isnumbercode(str){
        var digits="1234567890-/";
        var i=0;
        var strlen=str.length;
        while((i<strlen)){
                var char=str.charAt(i);
                if(digits.indexOf(char)==-1)return false;i++;
                                        }
        return true;
}
</script>

<script language=javascript>
function checkForm(theform){
  if (frm.job360.value==0) {
                alert("人才类型不能为空。");
                frm.job360.focus();
                return false;
        }        
  if (document.frm.username.value.length==0){
      alert("用户名不能为空。");
      mobj = eval("document.frm.username");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (document.frm.username.value.length<6){
      alert("用户名至少为六个字符。");
      mobj = eval("document.frm.username");
        mobj.focus()
        mobj.select()
          return false;
   }
    if (document.frm.password.value.length==0){
      alert("密码不能为空");
      mobj = eval("document.frm.password");
        mobj.focus()
        mobj.select()
          return false;
   }
     if (document.frm.password.value.length<6){
      alert("密码至少为六个字符。");
      mobj = eval("document.frm.password");
        mobj.focus()
        mobj.select()
          return false;
   }
    if (document.frm.password.value!=document.frm.repassword.value){
      alert("密码与确认密码不一致");
      mobj = eval("document.frm.repassword");
        mobj.focus()
        mobj.select()
          return false;
   }
    if (document.frm.name.value.length==0){
      alert("真实姓名不能为空");
      mobj = eval("document.frm.name");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (document.frm.idcode.value.length==0){
      alert("身份证号码不能为空");
      mobj = eval("document.frm.idcode");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (!isnumber(document.frm.idcode.value)){
   alert("身份证号码只能为数字");
      mobj = eval("document.frm.idcode");
        mobj.focus()
        mobj.select()
          return false;
   }
           if (!(document.frm.idcode.value.length==15||document.frm.idcode.value.length==18)) {
                window.alert ("您的身份证号码必须为15位或18位 !")
                mobj = eval("document.frm.idcode");
        mobj.focus()
        mobj.select()
                return false
        }
                if (!checkid(document.frm.idcode,document.frm.year,document.frm.month,document.frm.day)) {
                alert("身份证号码与出生年月不能对应,请填写正确身份证号码!");
                mobj = eval("document.frm.idcode");
        mobj.focus()
        mobj.select()
                return false
        }
         if (document.frm.education_content.value.length==0){
      alert("教育与培训背景不能为空");
      mobj = eval("document.frm.education_content");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (document.frm.workcompanynumber.value.length==0){
      alert("任职公司数不能为空");
      mobj = eval("document.frm.workcompanynumber");
        mobj.focus()
        mobj.select()
          return false;
   }
    if (!isnumber(document.frm.workcompanynumber.value)){
   alert("任职公司只能为数字");
      mobj = eval("document.frm.workcompanynumber");
        mobj.focus()
        mobj.select()
          return false;
   }
  if (document.frm.job_experience.value.length==0){
      alert("工作经历业绩不能为空");
      mobj = eval("document.frm.job_experience");
        mobj.focus()
        mobj.select()
          return false;
   }
   
   if (document.frm.remark.value.length==0){
      alert("自评报告不能为空");
      mobj = eval("document.frm.remark");
        mobj.focus()
        mobj.select()
          return false;
   }
    if (document.frm.jobaddress.value.length==0){
      alert("现工作地点不能为空");
      mobj = eval("document.frm.jobaddress");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (document.frm.objective.value.length==0){
      alert("求职意向不能为空");
      mobj = eval("document.frm.objective");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (document.frm.JobCat.value==0) {
                alert("请选择您要招聘的岗位类别。");
                document.frm.JobCat.focus();
                return false;
        }
        
   if (document.frm.deal.value.length==0){
      alert("待遇及其它要求不能为空");
      mobj = eval("document.frm.deal");
        mobj.focus()
        mobj.select()
          return false;
   }
    if (document.frm.tel.value.length==0&&document.frm.mobile.value.length==0)
{
                window.alert ("联系电话和手机必填一项!")
                mobj = eval("document.frm.tel");
        mobj.focus()
        mobj.select()
                return false
        }
        if (document.frm.tel.value.length>0)
{
          if (!isnumbercode(document.frm.tel.value)){
   alert("联系电话只能为数字和-");
      mobj = eval("document.frm.tel");
        mobj.focus()
        mobj.select()
          return false;
   }
   }
   if (document.frm.mobile.value.length>0){
          if (!isnumber(document.frm.mobile.value)){
   alert("手机号只能为数字");
      mobj = eval("document.frm.mobile");
        mobj.focus()
        mobj.select()
          return false;
   }
   }
           if (document.frm.email.value=='') {
                window.alert ("请输入您的E-mail地址 !")
                mobj = eval("document.frm.email");
        mobj.focus()
        mobj.select()
                return false
        }
        if ( !isEmail(document.frm.email.value,document.frm.email) )
           return false
         if (document.frm.address.value.length==0){
      alert("通信地址不能为空");
      mobj = eval("document.frm.address");
        mobj.focus()
        mobj.select()
          return false;
   }   
         if (document.frm.address.value.length<10){
      alert("通信地址至少为10个字符");
      mobj = eval("document.frm.address");
        mobj.focus()
        mobj.select()
          return false;
   }  
    if (document.frm.post_code.value.length==0){
      alert("邮政编码不能为空");
      mobj = eval("document.frm.post_code");
        mobj.focus()
        mobj.select()
          return false;
   }  
     if (!isnumber(document.frm.post_code.value)){
   alert("邮政编码只能为数字");
      mobj = eval("document.frm.post_code");
        mobj.focus()
        mobj.select()
          return false;
   }
   if (document.frm.post_code.value.length!=6){
      alert("邮政编码只能为六位");
      mobj = eval("document.frm.post_code");
        mobj.focus()
        mobj.select()
          return false;
   }   

  }
</script>
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
5#
 楼主| 发表于 2007-10-5 16:12:00 | 只看该作者
台州网址导航
<script language="JavaScript">
<!--

function check_telnum(str)
{
        var digits="1234567890-/";
        var i=0;
        var strlen=str.length;
        while((i<strlen))
        {
                var char=str.charAt(i);
                if(digits.indexOf(char)==-1)
                return false;i++;
        }
        return true;
}


function check()
{
        if(document.add.ctype.value==0)
        {
                        alert("请您选择客户类型!");
                        document.add.ctype.focus();
                        return false;
        }
        if(document.add.compname.value=="")
        {
                        alert("请您填入公司名称!");
                        document.add.compname.focus();
                        return false;
        }
    if(document.add.linker.value=="")
        {
                        alert("请您填入联系人!");
                        document.add.linker.focus();
                        return false;
        }
        if (document.add.linktel.value.length==0&&document.add.mobtel.value.length==0)
        {
                window.alert ("联系电话和手机请您填入一项!")
                document.add.linktel.focus();
                return false
        }
        /*if(document.add.linktel.value=="")
        {
                        alert("请您填入联系电话!");
                        document.add.linktel.focus();
                        return false;
        }*/
        if (document.add.linktel.value.length>0)
        {
                if (!check_telnum(document.add.linktel.value))
                {
                        alert("请您填入有效的联系电话!");
                        document.add.linktel.focus();
                        return false;
                }
    }
        if (document.add.mobtel.value.length>0)
        {
          if (isNaN(document.add.mobtel.value))
          {
                        alert("请您填入手机号只能为数字!");
                        document.add.mobtel.focus();
                        return false;
          }
   }
        if(document.add.compaddress.value=="")
        {
                        alert("请您填入公司地址!");
                        document.add.compaddress.focus();
                        return false;
        }
        if(isNaN(document.add.mblyear.value))
        {
                        alert("请您填入会员期限的年份只能为数字!");
                        document.add.mblyear.focus();
                        return false;isNaN
        }
        if(document.add.baer.value=="")
        {
                        alert("请您填入回访人!");
                        document.add.baer.focus();
                        return false;
        }       
        if(document.add.bayear.value=="")
        {
                        alert("请您填入回访日期的年份!");
                        document.add.bayear.focus();
                        return false;
        }
    if(isNaN(document.add.bayear.value))
        {
                        alert("请您填入会员期限的年份只能为数字!");
                        document.add.bayear.focus();
                        return false;
        }
        if(document.add.existproblem.value=="")
        {
                        alert("请您填入目前使用还存在的问题!");
                        document.add.existproblem.focus();
                        return false;
        }
        if(document.add.faid.value=="")
        {
                        alert("请您填入第一次回访的意见和建议!");
                        document.add.faid.focus();
                        return false;
        }
        if(document.add.fayear.value=="")
        {
                        alert("请您填入第一次回访意见和建议的年份!");
                        document.add.fayear.focus();
                        return false;
        }
        if(isNaN(document.add.fayear.value))
        {
                        alert("请您填入第一次回访意见和建议的年份为数字!");
                        document.add.fayear.focus();
                        return false;
        }
        /*else
        {
                   return true;
        }*/

  
}
-->
</script>
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表