标签:== func val ali php 信用卡 number span reg
1 /** 2 * 验证银行卡号是否是信用卡 3 * @param $cardnumber 4 * @return bool 5 */ 6 function validateCard ($cardnumber){ 7 $cardnumber = preg_replace ("/\D|\s/","", $cardnumber); 8 $cardlength = strlen($cardnumber);if($cardlength !=0){ 9 $parity = $cardlength %2; 10 $sum =0; 11 for($i=0; $i<$cardlength; $i++){ 12 $digit = $cardnumber[$i]; 13 if($i %2== $parity) $digit = $digit *2; 14 if($digit >9) $digit = $digit -9; 15 $sum = $sum + $digit; 16 } 17 $valid =($sum %10==0); 18 return $valid; 19 } 20 return false; 21 }
标签:== func val ali php 信用卡 number span reg
原文地址:https://www.cnblogs.com/aksir/p/9033129.html