文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php验证

php验证

时间:2010-04-26  来源:youkuiyuan

function isIdCardNo($num)
{
         //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X。
        if(preg_match("/^\d{14}(\d{1}|\d{4}|(\d{3}[xyXY]))$/",$num)==FALSE && $num!="")
        {
                  echo '输入的身份证号长度不对,或者号码不符合规定!15位号码应全为数字,18位号码末位可以为数字或X。';
                exit();
          }
}
function isTelCodeNo($num)
{
        if(preg_match("/^(^(\d{2,4}[-_-—]?)?\d{3,8}([-_-—]?\d{3,8})?([-_-—]?\d{1,7})?$)|(^0?1[35]\d{9}$)/",$num)==FALSE && $num!="")
        {
                  echo '您输入的电话号码有误!';
                echo "wrong";
                exit();
          }
}

function isPostCodeNo($num)
{
        if(preg_match("/[0-9]\d{5}(?!\d)/",$num)==FALSE && $num!="")
        {
                  echo '您输入的邮政编码有误!';
                echo "wrong";
                exit();
          }
}
function isEmailCodeNo($num)
{
        //echo $num;
        if(preg_match("/^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.){1,2}[a-z]{2,4}$/i",$num)==FALSE && $num!="")
        //if(preg_match("/^[a-z]([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/i",$num)==FALSE && $num!="")
        {
                  echo '您输入的邮箱格式有误!';
                echo "wrong";
                exit();
          }
}
function isNullNo($array,$arr=""){//$array 为上传的所有值 $arr 为不做判断的键值
        foreach($array as $key => $value){//循环判断开始
                if($arr !=""){//判断键值数组是否为空
                        if (in_array($key,$arr)){//键值是否在键值数组
                                continue;//跳出本次循环
                        }
                        else{//如果不在
                                if($value == ""){//判断本次数值是否为空
                                        //echo $key;
                                        echo "请仔细检查!有未填写的项目,如没有相应内容,请填写‘无’!";
                                        exit();
                                }
                        }
                
                }
                else{//如果没有键值数组
                        if($value == ""){//直接判断数值是否为空
                                //echo $key;
                                echo "请仔细检查!有未填写的项目,如没有相应内容,请填写‘无’!";
                                exit();
                        }
                }
        }
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载