diff --git a/Laravel/app/Lib/Tools.php b/Laravel/app/Lib/Tools.php index 1efe01b..db078aa 100644 --- a/Laravel/app/Lib/Tools.php +++ b/Laravel/app/Lib/Tools.php @@ -5,6 +5,10 @@ use DateTime; class Tools{ //根据当前日期和身份证获取年龄 public static function calculateAgeFromID($idNumber, $targetDate) { + // 检查身份证号码是否有效 + if (!preg_match("/^(\d{15}$|^\d{17}[xX\d]$)/", $idNumber)) { + return 0; + } // 提取出生年月日 $birthYear = substr($idNumber, 6, 4); $birthMonth = substr($idNumber, 10, 2);