首页  >  文章  >  后端开发  >  正则严厉验证身份证信息

正则严厉验证身份证信息

WBOY
WBOY原创
2016-06-13 12:13:32941浏览

正则严格验证身份证信息

<span style="color: #800080;">$a</span> = '130424770827005'<span style="color: #000000;">;</span><span style="color: #800080;">$reg18</span> = '/[1-9]\d{5}(((1[9|8])\d{2})|(20[0-1]\d))((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)/'<span style="color: #000000;">;</span><span style="color: #800080;">$reg15</span> = '/[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}/'<span style="color: #000000;">;问题是对年份进行了判断从1800到2019<br>等4年就需要修改。<br>其实还可以更严格些。</span><span style="color: #008080;">preg_match</span>(<span style="color: #800080;">$reg15</span>,<span style="color: #800080;">$a</span>,<span style="color: #800080;">$mm</span><span style="color: #000000;">);</span><span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$mm</span><span style="color: #000000;">);输出结果</span><span style="color: #0000ff;">array</span> (size=6<span style="color: #000000;">)  </span>0 => <span style="color: #0000ff;">string</span> '130424770827005' (length=15<span style="color: #000000;">)  </span>1 => <span style="color: #0000ff;">string</span> '08' (length=2<span style="color: #000000;">)  </span>2 => <span style="color: #0000ff;">string</span> '08' (length=2<span style="color: #000000;">)  </span>3 => <span style="color: #0000ff;">string</span> '' (length=0<span style="color: #000000;">)  </span>4 => <span style="color: #0000ff;">string</span> '27' (length=2<span style="color: #000000;">)  </span>5 => <span style="color: #0000ff;">string</span> '27' (length=2)

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn