Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function isValidIBAN($iban){
- if (strlen($iban) != 22){
- return false;
- }
- $str = substr($iban, 4) . substr($iban, 0, 4);
- $num = "";
- for($i = 0; $i < strlen($str); $i++){
- if (is_numeric($str[$i])){
- $num = $num . $str[$i];
- } else {
- $n = ord($str[$i]) - ord('A') + 10;
- $num = $num . $n;
- }
- }
- if (mod($num, 97) != 1){
- return false;
- }
- $str[20] = '0';
- $str[21] = '0';
- $num = "";
- for($i = 0; $i < strlen($str); $i++){
- if (is_numeric($str[$i])){
- $num = $num . $str[$i];
- } else {
- $n = ord($str[$i]) - ord('A') + 10;
- $num = $num . $n;
- }
- }
- $controlCalulated = 98 - mod($num, 97);
- $control = intval($iban[2].$iban[3]);
- if ($control != $controlCalulated){
- return false;
- }
- return true;
- }
- function mod($num, $a) {
- // Initialize result
- $res = 0;
- // One by one process
- // all digits of 'num'
- for ($i = 0; $i < strlen($num); $i++){
- $res = ($res * 10 + $num[$i] - '0') % $a;
- }
- return $res;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement