21,887
社区成员
发帖
与我相关
我的任务
分享
<?php require 'test_variable.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title>自定义字段检测函数</title>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="black" name="apple-mobile-web-app-status-bar-style"/>
<meta content="telephone=no" name="format-detection"/>
<meta content="email=no" name="format-detection"/>
<meta content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)" name="viewport"/>
<style>
</style>
</head>
<body>
<?php
$temp_str = array
(
//array([中文名称],[变量值],[必填/可选填],[变量值类型],[变量值长度限制类型],[变量值长度],[默认值:是否匹配单选/多选选项值])
array("姓名","张三",1,"zh",-1,5),
array("英文名","hello",1,"en",-1,5),
array("班级","201804",1,"num",-1,6),
array("地址","航银路25号",1,"mix",-1,6),
array("日期","2020/10/30 11:30",1,"date","","Y/m/d H:i"),
array("性别","男,女",1,"radio","","","女"),
array("学习科目","语文,数学,英语",1,"checkbox","","","语文"),
array("身份证号","45020320000406079X",0,"idnum")
);
echo "<div>--------</div>";
echo "<pre>";
var_dump($temp_str);
echo "</pre>";
echo "<div>--------</div>";
echo "<pre>";
var_dump(test_variable($temp_str));
echo "</pre>";
echo "<div>--------</div>";
?>
</body>
</html>
/*
标准格式
[0]str_cn:中文名称
[1]str_value:值
[2]str_required:1-必填,0-可选填
[3]str_type:类型。zh-中文,en-英文,num-数字,mix-混合(不限制中文、英文、数字),date-日期,radio-单选,checkbox-多选,idnum-身份证号
[4]str_lengthtype:字段长度限制类型。0-等于,1-大于等于,2-大于,-1小于等于,-2小于,9-不限制
[5]str_length:字段长度。填入数字,如5,配合str_lengthtype。
[6]str_match:设置单选/多选的默认值时,是否能匹配选项
*/
function test_variable($str_multiple) {
//以;分割,判断是否多组参数需要检测
for($i_multiple=0;$i_multiple<count($str_multiple);$i_multiple++){
//赋值单组参数
$str_single=$str_multiple[$i_multiple];
//中文类型 开始
//array("姓名","张三张三张三",1,"zh",-1,5)
if ($str_single[3]=="zh") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//非中文
elseif (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u',$str_single[1])<=0) {
$return_value="[".$str_single[0]."]必须为中文";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
//如为选填
elseif ($str_single[2]==0) {
//不为空执行检测
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//非中文
if (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u',$str_single[1])<=0) {
$return_value="[".$str_single[0]."]必须为中文";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
}
}
//中文类型 结束
//英文类型 开始
//array("姓名","smith",1,"en",-1,4)
if ($str_single[3]=="en") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//非英文
elseif (!preg_match("/^[a-zA-Z\s]+$/",$str_single[1])) {
$return_value="[".$str_single[0]."]必须为英文";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
//如为选填
elseif ($str_single[2]==0) {
//不为空执行检测
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//非英文
if (!preg_match("/^[a-zA-Z\s]+$/",$str_single[1])) {
$return_value="[".$str_single[0]."]必须为英文";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
}
}
//英文类型 结束
//数字类型 开始
//array("班级","201804",1,"num",-1,5)
if ($str_single[3]=="num") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//非数字
elseif (!preg_match("/^\d*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]必须为数字";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
//如为选填
elseif ($str_single[2]==0) {
//不为空执行检测
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//非数字
if (!preg_match("/^\d*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]必须为数字";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
}
}
//数字类型 结束
<?php
$arr = [
'name' => '张三李四王五赵六李白',
'age' => 2564
];
function main($arr){
$validate = [
'name'=>'datamust|dataMin:2|dataMax:6',
'age'=>'datamust|dataMin:1|dataMax:3'
];
$res = [];//结果
foreach ($validate as $key=>$val){
foreach ($arr as $k=>$item){
if ($key==$k){
$val_arr = explode('|',$val);
foreach ($val_arr as $ty){
$tt = explode(':',$ty);
if (count($tt)<2){
$ires = $tt[0]($key,$item);
if ($ires){
$res = array_merge($res,[$ires]);
break;
}
}else{
$ires = $tt[0]($key,$item,$tt[1]);
if ($ires){
$res = array_merge($res,[$ires]);
break;
}
}
}
}
}
}
if (count($res)>0){
var_dump($res);
}
}
function dataMin($key, $col, $standard)
{
if (mb_strlen($col) < $standard) {
return $key . '长度大于' . $standard;
};
}
function dataMax($key, $col, $standard)
{
if (mb_strlen($col) > $standard) {
return $key . '长度小于' . $standard;
};
}
function datamust($key, $col)
{
if (!$col) {
return $key . "不能为空";
}
}
main($arr);
//这是原来的代码
//如果使用这段。非空时,中文检测是使用elseif
//也就是说,“值”是空的话,函数不去检测是否为中文的代码
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//非中文
elseif (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u',$str_single[1])<=0) {
$return_value="[".$str_single[0]."]必须为中文";
}
//这是增加子函数后简化的代码
//如果使用这段
//也就是说,“值”是空的话,函数还是需要去检测是否为中文
//定义子函数
function str_value_null($str_cn,$str_value) {
if (preg_match("/^[\\s]*$/",$str_value)) {
return $return_value="[".$str_cn."]不能为空";
}
}
function str_value_zh($str_cn,$str_value) {
此处省略;
}
//为空
str_value_null($str_single[0],$str_single[1]);
//非中文
str_value_zh($str_single[0],$str_single[1]);
如果自定义子函数的话(思路写在代码备注里)
1、无论是不是空,还得继续检测是否中文——是否影响执行效率?
2、检测时,值为空会出错,因为是null
我存在这些疑问,请指点
//混合类型 开始
//array("地址","航银路25号",1,"mix",-1,5)
if ($str_single[3]=="mix") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//判断字段长度限制类型
//等于
elseif ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
//如为选填
elseif ($str_single[2]==0) {
//不为空执行检测
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//判断字段长度限制类型
//等于
if ($str_single[4]==0) {
if (mb_strlen($str_single[1],"utf-8")!=$str_single[5]) {
$return_value="[".$str_single[0]."]必须等于[".$str_single[5]."]位";
}
}
//大于等于
elseif ($str_single[4]==1) {
if (mb_strlen($str_single[1],"utf-8")<$str_single[5]) {
$return_value="[".$str_single[0]."]不能小于[".$str_single[5]."]位";
}
}
//大于
elseif ($str_single[4]==2) {
if (mb_strlen($str_single[1],"utf-8")<=$str_single[5]) {
$return_value="[".$str_single[0]."]必须大于[".$str_single[5]."]位";
}
}
//小于等于
elseif ($str_single[4]==-1) {
if (mb_strlen($str_single[1],"utf-8")>$str_single[5]) {
$return_value="[".$str_single[0]."]不能大于[".$str_single[5]."]位";
}
}
//小于
elseif ($str_single[4]==-2) {
if (mb_strlen($str_single[1],"utf-8")>=$str_single[5]) {
$return_value="[".$str_single[0]."]必须小于[".$str_single[5]."]位";
}
}
}
}
}
//混合类型 结束
//日期类型 开始
//array("日期","2020/10/30 11:30:20",1,"date","","Y/m/d H:i")
if ($str_single[3]=="date") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//非日期格式
elseif (date_format(date_create($str_single[1]),$str_single[5])!=$str_single[1]) {
$return_value="[".$str_single[0]."]格式错误";
}
}
//如为选填
elseif ($str_single[2]==0) {
//不为空执行检测
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//非日期格式
if (date_format(date_create($str_single[1]),$str_single[5])!=$str_single[1]) {
$return_value="[".$str_single[0]."]格式错误";
}
}
}
}
//日期类型 结束
//单选类型 开始
//array("性别","男,女,男",1,"radio","","","未知,男")
if ($str_single[3]=="radio") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//不为空时检测
else {
//选项中有重复值
for($i_repeat=0;$i_repeat<count(explode(",",$str_single[1]));$i_repeat++) {
if ( array_count_values(explode(",",$str_single[1]))[explode(",",$str_single[1])[$i_repeat]]>1 ) {
$return_value="单选选项[".$str_single[0]."]中有重复值";
}
}
//如果默认值不为空
if (!preg_match("/^[\\s]*$/",$str_single[6])) {
//是否存在多个默认选项
if ( count(explode(",",$str_single[6]))>1 ) {
$return_value="单选选项[".$str_single[0]."]只能有1个默认值";
}
//默认选项是否匹配选项
if ( is_null(array_count_values(explode(",",$str_single[1]))[$str_single[6]]) ) {
$return_value="单选选项[".$str_single[0]."]的默认值不匹配";
}
}
}
}
//如为选填
if ($str_single[2]==0) {
//不为空
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//选项中有重复值
for($i_repeat=0;$i_repeat<count(explode(",",$str_single[1]));$i_repeat++) {
if ( array_count_values(explode(",",$str_single[1]))[explode(",",$str_single[1])[$i_repeat]]>1 ) {
$return_value="单选选项[".$str_single[0]."]中有重复值";
}
}
//如果默认值不为空
if (!preg_match("/^[\\s]*$/",$str_single[6])) {
//是否存在多个默认选项
if ( count(explode(",",$str_single[6]))>1 ) {
$return_value="单选选项[".$str_single[0]."]只能有1个默认值";
}
//默认选项是否匹配选项
if ( is_null(array_count_values(explode(",",$str_single[1]))[$str_single[6]]) ) {
$return_value="单选选项[".$str_single[0]."]的默认值不匹配";
}
}
}
}
}
//单选类型 结束
//多选类型 开始
//array("学习科目","语文,数学,英语,语文",1,"checkbox","","","女")
if ($str_single[3]=="checkbox") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//不为空时检测
else {
//选项中有重复值
for($i_repeat=0;$i_repeat<count(explode(",",$str_single[1]));$i_repeat++) {
if ( array_count_values(explode(",",$str_single[1]))[explode(",",$str_single[1])[$i_repeat]]>1 ) {
$return_value="多选选项[".$str_single[0]."]中有重复值";
}
}
//如果默认值不为空
if (!preg_match("/^[\\s]*$/",$str_single[6])) {
//默认选项是否匹配选项
for($i_checkbox=0;$i_checkbox<count(explode(",",$str_single[6]));$i_checkbox++) {
if ( is_null(array_count_values(explode(",",$str_single[1]))[explode(",",$str_single[6])[$i_checkbox]]) ) {
$return_value="多选选项[".$str_single[0]."]的默认值不匹配";
}
}
}
}
}
//如为选填
if ($str_single[2]==0) {
//不为空
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//选项中有重复值
for($i_repeat=0;$i_repeat<count(explode(",",$str_single[1]));$i_repeat++) {
if ( array_count_values(explode(",",$str_single[1]))[explode(",",$str_single[1])[$i_repeat]]>1 ) {
$return_value="多选选项[".$str_single[0]."]中有重复值";
}
}
//如果默认值不为空
if (!preg_match("/^[\\s]*$/",$str_single[6])) {
//默认选项是否匹配选项
for($i_checkbox=0;$i_checkbox<count(explode(",",$str_single[6]));$i_checkbox++) {
if ( is_null(array_count_values(explode(",",$str_single[1]))[explode(",",$str_single[6])[$i_checkbox]]) ) {
$return_value="多选选项[".$str_single[0]."]的默认值不匹配";
}
}
}
}
}
}
//多选类型 结束
//身份证号 开始
//array("身份证号","45020320000406079",1,"idnum")
if ($str_single[3]=="idnum") {
//如为必填
if ($str_single[2]==1) {
//为空
if (preg_match("/^[\\s]*$/",$str_single[1])) {
$return_value="[".$str_single[0]."]不能为空";
}
//必须为18位
elseif (mb_strlen($str_single[1],"utf-8")<>18) {
$return_value="[".$str_single[0]."]必须为18位";
}
//前17位只能为数字
elseif (!preg_match("/^\d*$/",mb_substr($str_single[1],0,17))) {
$return_value="[".$str_single[0]."]前17位只能为数字";
}
//前2位行政区域代码
elseif (!in_array(mb_substr($str_single[1],0,2),array(11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91))) {
$return_value="[".$str_single[0]."]前2位行政区域错误";
}
//生日错误
elseif (!checkdate(ltrim(mb_substr($str_single[1],10,2),'0'),ltrim(mb_substr($str_single[1],12,2),'0'),mb_substr($str_single[1],6,4))) {
$return_value="[".$str_single[0]."]生日错误";
}
//校验码,根据国家标准GB 11643-1999
$coefficient=array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
$idnumber_sum=0;
for ($i_idnum=0;$i_idnum<mb_strlen($str_single[1]);$i_idnum++)
{
$idnumber_sum+= mb_substr($str_single[1],$i_idnum,1)*$coefficient[$i_idnum];
}
$idnumber_mod=$idnumber_sum%11;
//校验码对应值
$verify_number_list=array(1,0,X,9,8,7,6,5,4,3,2);
if (mb_substr($str_single[1],17,1)!=$verify_number_list[$idnumber_mod]) {
$return_value="[".$str_single[0]."]校验码错误";
}
}
//如为选填
if ($str_single[2]==0) {
//为空
if (!preg_match("/^[\\s]*$/",$str_single[1])) {
//必须为18位
if (mb_strlen($str_single[1],"utf-8")<>18) {
$return_value="[".$str_single[0]."]必须为18位";
}
//前17位只能为数字
elseif (!preg_match("/^\d*$/",mb_substr($str_single[1],0,17))) {
$return_value="[".$str_single[0]."]前17位只能为数字";
}
//前2位行政区域代码
elseif (!in_array(mb_substr($str_single[1],0,2),array(11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91))) {
$return_value="[".$str_single[0]."]前2位行政区域错误";
}
//生日错误
elseif (!checkdate(ltrim(mb_substr($str_single[1],10,2),'0'),ltrim(mb_substr($str_single[1],12,2),'0'),mb_substr($str_single[1],6,4))) {
$return_value="[".$str_single[0]."]生日错误";
}
//校验码,根据国家标准GB 11643-1999
$coefficient=array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
$idnumber_sum=0;
for ($i_idnum=0;$i_idnum<mb_strlen($str_single[1]);$i_idnum++)
{
$idnumber_sum+= mb_substr($str_single[1],$i_idnum,1)*$coefficient[$i_idnum];
}
$idnumber_mod=$idnumber_sum%11;
//校验码对应值
$verify_number_list=array(1,0,X,9,8,7,6,5,4,3,2);
if (mb_substr($str_single[1],17,1)!=$verify_number_list[$idnumber_mod]) {
$return_value="[".$str_single[0]."]校验码错误";
}
}
}
}
//身份证号 结束
//返回
//单个循环结束前判断并跳出,保证按数组顺序检测输出
if (!preg_match("/^[\\s]*$/",$return_value)) {
return array("false",$return_value);
}
}
}