TypechoJoeTheme

来鹏飞

统计

来鹏飞

简单的事情做到极致~
网站页面
类目归类
标签搜索
PHP

PHP验证输入身份证号 是否正确 亲测有效

2021-08-07
/
1 评论
/
202 阅读
/
正在检测是否收录...
08/07

PHP验证输入身份证号 是否正确 亲测有效



/**
 * php验证身份证号码是否正确函数
 * @param $id
 * @return bool
 */
function is_idcard($id)
{
    $id = strtoupper($id);
    $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
    $arr_split = array();
    if(!preg_match($regx, $id))
    {
        return FALSE;
    }
    if(15==strlen($id)) //检查15位
    {
        $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";

        @preg_match($regx, $id, $arr_split);
        //检查生日日期是否正确
        $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
        if(!strtotime($dtm_birth))
        {
            return FALSE;
        } else {
            return TRUE;
        }
    }
    else      //检查18位
    {
        $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
        @preg_match($regx, $id, $arr_split);
        $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
        if(!strtotime($dtm_birth)) //检查生日日期是否正确
        {
            return FALSE;
        }
        else
        {
            //检验18位身份证的校验码是否正确。
            //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
            $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            $sign = 0;
            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;
            } //phpfensi.com
            else
            {
                return TRUE;
            }
        }
    }
}
赞 · 3
赞赏
感谢您的支持,我会继续努力哒!

三合一收款

下面三种方式都支持哦

微信
QQ
支付宝
打开支付宝/微信/QQ扫一扫,即可进行扫码打赏哦
版权属于:

来鹏飞

本文链接:

http://www.appmmm.cn/index.php/archives/95.html(转载时请注明本文出处及文章链接)

评论 (1)
  1. 来鹏飞 作者
    Windows 10 · Google Chrome

    {!{data:image/webp;base64,UklGRvAXAABXRUJQVlA4WAoAAAAQAAAAAQMAKwEAQUxQSEISAAAN8Eft/yyl0badEqsE2Updhti7O+UlChlJL+uK9pREMWiuOOZCM6iduMCIxqGFwuEiwxUokitRLrRFEpwuEiGTOJKoVCBGpJpKmgz22pazFhGW5crOaCFbxULNHwxCVe2qtX7XQERMAL3+7/V/r/97/d/r/17/9/q/1///P9GKP36Zq4h9M+D3wwvFvuGAgtj/W/j8S8FvGixG7E+HS2cEP03iIoK/BBE3BD9VRkPw1yS8ol8CmD2CnyrjQ/CXof9lwS8KIlsFP+AXBH8Jbrku+FVOJurpErHPdX4i2fliH1+PYsg5sc9aA/2mlYt8llS++xUFK0S+VWAA80Pl4p4CfNX2AAUrhL0cYG/xiHzM83JFvWXw1as4o0aSuU7Ms+yAtsnA+kWI+aYKE1AD8M1wGkW82kSg5Z297SwwouqpOsHOsgPg/EQ6rEkGuWC2WFcbAzRvfIOOXbPfGcHQIU6RLgfQyl6ii66XPwJHvl2YM229AQ0pdL1poZ2I9QtEuar7gWt/5GY/Pp3JrT8Jcum0P8DNN8TT/36nGDcSbmw+dK4b9jwGjpecgo6lcNTlVoPHJHk0s+TRzJJHMw/2XTG0GdoMntiIV0uCi+MG7PmY7mxaaCfC8VapgGMp/B3QPxIzmCUwS2CWwBiFAQNmeDllTZUSPPYA1+bRvR9v2Q5b3nKKNo5R+GPssgl3f/+0Mzh8CXCA7t5RWQqOfLtY00j71oojP6iyW5LdSLIbSXYjDbuiyqqsym55QRIQOTh/VlCYA/zt3XPdRtnBUiLeXCTSmOqBq/ucGwFUNBU0FTQVtLOgoqKibrww35w8APPe2BsL7YFWfx0uT6Qny7yZDL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