Home >php教程 >PHP源码 >php验证台湾身份证号码是否合法

php验证台湾身份证号码是否合法

PHP中文网
PHP中文网Original
2016-05-26 08:18:231783browse

1. [代码][PHP]代码  

/**
	驗證台灣身份證號碼
	参数:
		身份證號碼
	返回:
		布爾值
	用法:
		echo &#39;<pre class="brush:php;toolbar:false">&#39;,var_dump(Fun::twcod(&#39;n2......10&#39;)),&#39;
'; /**/ public static function twcod($id) { $id=strtoupper($id); $d1=substr($id,0,1); if(strlen($id)!=10) {return FALSE;} if(stristr('ABCDEFGHJKLMNPQRSTUVXYWZIO',$d1)===FALSE) {return FALSE;} if(substr($id,1,1)!='1' && substr($id,1,1)!='2') {return FALSE;} if(!is_numeric(substr($id,1,9))) {return FALSE;} $num=array( 'A'=>'10','B'=>'11','C'=>'12','D'=>'13','E'=>'14','F'=>'15','G'=>'16','H'=>'17','J'=>'18','K'=>'19','L'=>'20','M'=>'21','N'=>'22', 'P'=>'23','Q'=>'24','R'=>'25','S'=>'26','T'=>'27','U'=>'28','V'=>'29','X'=>'30','Y'=>'31','W'=>'32','Z'=>'33','I'=>'34','O'=>'35', ); $n1=substr($num[$d1],0,1)+(substr($num[$d1],1,1)*9); unset($num,$d1); $n2=0; for($j=1;$j<9;$j++) { $d4=substr($id,$j,1); $n2=$n2+$d4*(9-$j); } $n3=$n1+$n2+substr($id,9,1); if(($n3 % 10)!=0){return FALSE;} return TRUE; }

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn