From 0658dfdf148a0da8127b3364d013ebccc28a089c Mon Sep 17 00:00:00 2001 From: yanzai Date: Thu, 21 Nov 2024 22:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=B9=B4=E9=BE=84=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20=E6=A0=A1=E9=AA=8C=E8=BA=AB=E4=BB=BD=E8=AF=81?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Laravel/app/Lib/Tools.php | 4 ++++ 1 file changed, 4 insertions(+) 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);