企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ if (!function_exists('verifyPhone')) { /** * 验证手机号格式是否正确 */ function verifyPhone($mobile) { if (!is_numeric($mobile) || strlen($mobile) < 11) { return false; } return preg_match("/^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[\d]{9}$|^18[\d]{9}$/", $mobile) === 1; } } ~~~ ~~~ if (!function_exists('verifyEmail')) { /** * 验证邮箱格式是否正确 */ function verifyEmail($email) { return preg_match("/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i", $email) === 1; } } ~~~ ~~~ if (!function_exists('verifyIdCard')) { /** * 验证身份证号码是否正确 */ function verifyIdCard($id) { $IdRe15 = '/^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/'; $IdRe18 = '/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/'; if (preg_match($IdRe15, $id) || preg_match($IdRe18, $id)) { return true; } return false; $id = strtoupper($id); $card = []; if (!preg_match("/(^\d{15}$)|(^\d{17}([0-9]|X)$)/", $id)) { return false; } if (strlen($id) == 15) { preg_match("/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/", $id, $card); if (!strtotime("19{$card[2]}/{$card[3]}/{$card[4]}")) { return false; } return true; } preg_match("/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/", $id, $card); if (!strtotime("{$card[2]}/{$card[3]}/{$card[4]}")) { return false; } $sign = 0; $arr_ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; $arr_int = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; for ($i = 0; $i < 17; $i++) { $b = (int)$id{$i}; $w = $arr_int[$i]; $sign += $b * $w; } $n = $sign % 11; $val_num = $arr_ch[$n]; if ($val_num != substr($id, 17, 1)) { return false; } return true; } } ~~~ ~~~ if (!function_exists('getBirthdayFromCard')) { /** * 根据身份证号码获取生日 */ function getBirthdayFromCard($id_card) { if (empty($id_card)) { return null; } if (strlen($id_card) == 15) { $day = substr($id_card, 10, 2); $year = '19' . substr($id_card, 6, 2); $month = substr($id_card, 8, 2); } else { $bir = substr($id_card, 6, 8); $day = substr($bir, 6, 2); $year = substr($bir, 0, 4); $month = substr($bir, 4, 2); } return implode('/', [$year, $month, $day]); } } ~~~ ~~~ if (!function_exists('getSexFromCard')) { /** * 根据身份证号码获取性别 */ function getSexFromCard($id_card) { if (empty($id_card)) { return null; } $sex = (int)substr($id_card, 16, 1); return $sex % 2 === 0 ? '女' : '男'; } } ~~~ ~~~ if (!function_exists('getAgeFromCard')) { /** * 根据身份证号码获取年龄 */ function getAgeFromCard($id_card) { if (empty($id_card)) { return null; } $date = strtotime(substr($id_card, 6, 8)); $today = strtotime('today'); $diff = floor(($today - $date) / 86400 / 365); $age = strtotime(substr($id_card, 6, 8) . ' +' . $diff . 'years') > $today ? ($diff + 1) : $diff; return intval($age); } } ~~~ ~~~ // 验证是否是银行卡 if (!function_exists('verifyBankcard')) { function verifyBankcard($card_number) { $arr_no = str_split($card_number); $last_n = $arr_no[count($arr_no) - 1]; krsort($arr_no); $i = 1; $total = 0; foreach ($arr_no as $n) { if ($i % 2 == 0) { $ix = $n * 2; if ($ix >= 10) { $nx = 1 + ($ix % 10); $total += $nx; } else { $total += $ix; } } else { $total += $n; } $i++; } $total -= $last_n; $x = 10 - ($total % 10); if ($x == $last_n) { return true; } else { return false; } } } ~~~