How to realize Bank Card Verification by php
This article is to share with you about how php implements bank card verification. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. The implementation code is as follows / * verify whether the bank card number * @ param string $bankCardNo bank card number * @ return bool is legal (true: legal, false: illegal) * / function checkBankCard ($bankCardNo) {$strlen = strlen ($bankCardNo); if ($strlen)
< 15 || $strlen >19) {return false } if (! preg_match ("/ ^\ d {15} $/ I", $bankCardNo) & &! preg_match ("/ ^\ d {16} $/ I", $bankCardNo) & &! preg_match ("/ ^\ d {17} $/ I", $bankCardNo) & &! preg_match ("/ ^\ d {18} $/ I" $bankCardNo) & &! preg_match ("/ ^\ d {19} $/ I", $bankCardNo)) {return false } $arr_no = str_split ($bankCardNo); $last_n = $arr_no [count ($arr_no)-1]; krsort ($arr_no); $I = 1; $total = 0; foreach ($arr_no as $n) {if ($I% 2room0) {$ix = $Nation2 If ($ix > = 10) {$nx = 1 + ($ix% 10); $total + = $nx;} else {$total + = $ix;}} else {$total + = $n;} $iTunes + } $total-= $last_n; $x = 10-($total% 10); if ($x! = $last_n) {return false;} return true;} Thank you for reading! This is the end of this article on "how to achieve bank card verification in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!