Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function ibanCheck($iban){
- /*if (strlen($iban) != 22){
- return false;
- }
- if ($iban[0] != 'B' || $iban[1] != 'G'){
- return false;
- }*/
- $len = array("BG"=>22, "DK"=>18, "AT"=>20);
- $patternIBAN = "/^[0-9A-Z]+$/";
- if (!preg_match($patternIBAN, $iban)){
- return false;
- }
- $countryCode = $iban[0].$iban[1];
- if (!array_key_exists($countryCode, $len)){
- return false;
- }
- if (strlen($iban) != $len[$countryCode]){
- 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 = substr($iban, 4) . substr($iban, 0, 4);
- $str[strlen($str) - 1] = $str[strlen($str) - 2] = '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;
- }
- }
- $controlNumberCalculated = 98 - mod($num, 97);
- $controlNumberReal = intval($iban['2'].$iban['3']); //substr($iban, 2, 2)
- if ($controlNumberCalculated != $controlNumberReal){
- 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