public function VerifyMachineFormatOnly($iban = '')
 {
     if ($iban != '') {
         return verify_iban($iban, true);
     }
     return verify_iban($this->iban, true);
 }
Exemple #2
0
function verify_and_format_iban($IBAN)
{
    if (!verify_iban($IBAN)) {
        throw new Exception("IBAN {$IBAN} is ongeldig");
    }
    return iban_to_machine_format($IBAN);
}
 private function buildIban($controlNumber, $bban)
 {
     $iban = $this->country . $controlNumber . $bban;
     if (!verify_iban($iban)) {
         throw new IbanConvertorException("Iban is in invalid format");
     }
     return $iban;
 }
 /**
  * Verifies if the given IBAN is formally correct
  *
  * @param iban  string, IBAN candidate
  *
  * @return NULL if given IBAN is valid, localized error message otherwise
  */
 static function verifyIBAN($iban)
 {
     // We only accept uppecase characters and numerals (machine format)
     // see https://github.com/Project60/org.project60.sepa/issues/246
     if (!preg_match("/^[A-Z0-9]+\$/", $iban)) {
         return ts("IBAN is not correct");
     }
     if (verify_iban($iban)) {
         return NULL;
     } else {
         return ts("IBAN is not correct");
     }
 }
Exemple #5
0
 public function Verify($iban = '')
 {
     if ($iban != '') {
         return verify_iban($iban);
     }
     return verify_iban($this->iban);
     # we could throw exceptions of various types, but why - does it really
     # add anything? possibly some slightly better user feedback potential.
     # however, this can be written by hand by performing individual checks
     # ala the code in verify_iban() itself where required, which is likely
     # almost never. for the increased complexity and
     # maintenance/documentation cost, i say, therefore: no. no exceptions.
 }
Exemple #6
0
function check_IBAN($iban)
{
    $machine_iban = iban_to_machine_format($iban);
    if (verify_iban($machine_iban)) {
        $array['result'] = false;
        $array['human_IBAN'] = iban_to_human_format($machine_iban);
        echo json_encode($array);
    } else {
        $array['result'] = true;
        $array['message'] = "Nesprávny iban";
        echo json_encode($array);
    }
}
Exemple #7
0
function iban_to_human_format($iban)
{
    # First verify validity, or return
    if (!verify_iban($iban)) {
        return false;
    }
    # Add spaces every four characters
    $tr = '';
    for ($i = 0; $i < strlen($iban); $i++) {
        $tr .= substr($iban, $i, 1);
        if ($i > 0 && ($i + 1) % 4 == 0) {
            $tr .= ' ';
        }
    }
    return $tr;
}
 public function validateForm(array &$element, array &$form_state, \Payment $payment)
 {
     $values =& \Drupal\Component\Utility\NestedArray::getValue($form_state['values'], $element['#parents']);
     $method_data =& $payment->method_data;
     $method_data['holder'] = $values['holder'];
     if (empty($values['holder']) == TRUE) {
         form_error($element['holder'], t('Please enter the name of the account holder.'));
     }
     $method_data['iban'] = trim($values['ibanbic']['iban']);
     $method_data['bic'] = trim($values['ibanbic']['bic']);
     $method_data['country'] = substr($method_data['iban'], 0, 2);
     require_once dirname(__FILE__) . '/../php-iban.php';
     if (verify_iban($method_data['iban']) == FALSE) {
         form_error($element['ibanbic']['iban'], t('Please enter a valid IBAN.'));
     }
     if (preg_match('/^[a-z]{6}[2-9a-z][0-9a-np-z](|xxx|[0-9a-wyz][0-9a-z]{2})$/i', $method_data['bic']) != 1) {
         form_error($element['ibanbic']['bic'], t('Please enter a valid BIC.'));
     }
 }
Exemple #9
0
<?php

# additional tests library
#  - first we enable error display
ini_set('display_errors', 1);
#  - next we ensure that all errors are displayed
ini_set('error_reporting', E_ALL);
# include the library itself
require_once dirname(dirname(__FILE__)) . '/php-iban.php';
print "Other tests:\n";
# === verify_iban machine_format_only mode ===============================
$test_data = array(array('GB29 NWBK 6016 1331 9268 19', true, false), array('GB29 NWBK 6016 1331 9268 19', false, true), array('IBAN GB29-NWBK-6016-1331-9268 19', true, false), array('IBAN GB29-NWBK-6016-1331-9268 19', false, true), array('IIBAN GB29-NWBK-6016-1331-9268 19', false, true));
$i = 0;
foreach ($test_data as $this_test) {
    print " - verify_iban() test #{$i}... ";
    if (verify_iban($this_test[0], $this_test[1]) !== $this_test[2]) {
        print "FAILED.\n";
        exit(1);
    } else {
        print "OK.\n";
    }
    $i++;
}
# === swift_official field ===================================
print " - SWIFT official check for 'AA'... ";
if (iban_country_get_country_swift_official('AA')) {
    print "FAILED.\n";
    exit(1);
} else {
    print "OK.\n";
}
 /**
  * @param $value
  * @return bool
  */
 public function checkIBAN($value)
 {
     return verify_iban($value);
 }
if (!isset($argv[1]) || $argv[1] == '-h' || $argv[1] == '--help') {
    usage();
}
$list_file = $argv[1];
$errors = 0;
if (!($raw_list = file_get_contents($list_file))) {
    print "Error opening list file '{$list_file}'.\n";
    exit(1);
}
$list = preg_split("/[\r\n]+/", $raw_list);
$results = array();
foreach ($list as $iban) {
    if ($iban != '') {
        # let's check it
        print $iban . " ... ";
        if (!verify_iban($iban)) {
            print "FAILED";
            ########## try to provide better output #############
            $iban = iban_to_machine_format($iban);
            $country = iban_get_country_part($iban);
            $observed_length = strlen($iban);
            $expected_length = iban_country_get_iban_length($country);
            if ($observed_length != $expected_length) {
                print " (length {$observed_length} does not match expected length {$expected_length} for country {$country})";
            }
            $checksum = iban_get_checksum_part($iban);
            if (!iban_verify_checksum($iban)) {
                print " (checksum {$checksum} invalid)";
            }
            $regex = '/' . iban_country_get_iban_format_regex($country) . '/';
            if (!preg_match($regex, $iban)) {
Exemple #12
0
    print "Is a SEPA member? ";
    if (iban_country_is_sepa($countrycode)) {
        print "Yes";
    } else {
        print "No";
    }
    print ".\n";
    # get example iban
    $iban = $country['iban_example'];
    # output example iban properties one by one
    print "Example IBAN: " . iban_to_human_format($iban) . "\n";
    print " - country  " . iban_get_country_part($iban) . "\n";
    print " - checksum " . iban_get_checksum_part($iban) . "\n";
    print " - bban     " . iban_get_bban_part($iban) . "\n";
    print " - bank     " . iban_get_bank_part($iban) . "\n";
    print " - branch   " . iban_get_branch_part($iban) . "\n";
    print " - account  " . iban_get_account_part($iban) . "\n";
    # output all properties
    #$parts = iban_get_parts($iban);
    #print_r($parts);
    # verify
    print "\nChecking validity... ";
    if (verify_iban($iban)) {
        print "IBAN {$iban} is valid.\n";
    } else {
        print "ERROR: IBAN {$iban} is invalid.\n";
        $errors++;
    }
    print "\n";
}
exit($errors);
Exemple #13
0
function iban_mistranscription_suggestions($incorrect_iban)
{
    # abort on ridiculous length input (but be liberal)
    $length = strlen($incorrect_iban);
    if ($length < 5 || $length > 34) {
        return array('(supplied iban length insane)');
    }
    # abort if mistranscriptions data is unable to load
    if (!_iban_load_mistranscriptions()) {
        return array('(failed to load mistranscriptions)');
    }
    # init
    global $_iban_mistranscriptions;
    $suggestions = array();
    # we have a string of approximately IBAN-like length.
    # ... now let's make suggestions.
    $numbers = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
    for ($i = 0; $i < $length; $i++) {
        # get the character at this position
        $character = substr($incorrect_iban, $i, 1);
        # for each known transcription error resulting in this character
        foreach ($_iban_mistranscriptions[$character] as $possible_origin) {
            # if we're:
            #  - in the first 2 characters (country) and the possible replacement
            #    is a letter
            #  - in the 3rd or 4th characters (checksum) and the possible
            #    replacement is a number
            #  - later in the string
            if ($i < 2 && !in_array($possible_origin, $numbers) || $i >= 2 && $i <= 3 && in_array($possible_origin, $numbers) || $i > 3) {
                # construct a possible IBAN using this possible origin for the
                # mistranscribed character, replaced at this position only
                $possible_iban = substr($incorrect_iban, 0, $i) . $possible_origin . substr($incorrect_iban, $i + 1);
                # if the checksum passes, return it as a possibility
                if (verify_iban($possible_iban)) {
                    array_push($suggestions, $possible_iban);
                }
            }
        }
    }
    # now we check for the type of mistransposition case where all of
    # the characters of a certain type within a string were mistransposed.
    #  - first generate a character frequency table
    $char_freqs = array();
    for ($i = 0; $i < strlen($incorrect_iban); $i++) {
        if (!isset($char_freqs[substr($incorrect_iban, $i, 1)])) {
            $char_freqs[substr($incorrect_iban, $i, 1)] = 1;
        } else {
            $char_freqs[substr($incorrect_iban, $i, 1)]++;
        }
    }
    #  - now, for each of the characters in the string...
    foreach ($char_freqs as $char => $freq) {
        # if the character occurs more than once
        if ($freq > 1) {
            # check the 'all occurrences of <char> were mistranscribed' case
            foreach ($_iban_mistranscriptions[$char] as $possible_origin) {
                $possible_iban = str_replace($char, $possible_origin, $incorrect_iban);
                if (verify_iban($possible_iban)) {
                    array_push($suggestions, $possible_iban);
                }
            }
        }
    }
    return $suggestions;
}
 public function isValid($value)
 {
     $sanitized = preg_replace('/\\s/', '', $value);
     return verify_iban($sanitized, true);
 }
 /**
  * Normalise a reference (if a normalisation is available)
  *
  * @param $reference_type_name the name of the type, e.g. IBAN, NBAN_DE, ...
  *
  * @return  FALSE if no normalisation is possible (not implemented)
  *          0     if doesn't comply with standard 
  *          1     if reference is already normalised
  *          2     if reference was normalised
  */
 public static function normalise($reference_type_name, &$reference)
 {
     $match = array();
     switch ($reference_type_name) {
         case 'IBAN':
             $structure_correct = self::std_normalisation($reference_type_name, $reference, "#^(?P<IBAN>[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16})\$#", "%s");
             if (!$structure_correct) {
                 return $structure_correct;
             } else {
                 // structure correct, check the checksum...
                 if (TRUE == (include 'packages/php-iban-1.4.0/php-iban.php') && function_exists('verify_iban')) {
                     if (verify_iban($reference)) {
                         return $structure_correct;
                     } else {
                         return 0;
                     }
                 } else {
                     // this means we cannot check beyond structural compliance...
                     //   ...but what can we do?
                     return $structure_correct;
                 }
             }
             return FALSE;
             // we shouldn't get here
         // we shouldn't get here
         case 'NBAN_DE':
             return self::std_normalisation($reference_type_name, $reference, "#^(?P<BLZ>\\d{8})/(?P<KTO>\\d{2,10})\$#", "%08d/%010d");
         case 'NBAN_CH':
             return self::std_normalisation($reference_type_name, $reference, "#^(?P<PRE>\\d{1,2})-(?P<KTO>\\d{2,9})-(?P<SUF>\\d{1})\$#", "%02d-%09d-%01d");
         case 'NBAN_CZ':
             // first, try with prefix
             $result = self::std_normalisation($reference_type_name, $reference, "#^(?P<PREFIX>\\d{1,6})-(?P<ACCT>\\d{1,10})/(?P<BANK>\\d{1,4})\$#", "%06d-%010d/%04d");
             if ($result) {
                 return $result;
             } else {
                 // if failed, try with shortened form (no prefix)
                 return self::std_normalisation($reference_type_name, $reference, "#^(?P<ACCT>\\d{1,10})/(?P<BANK>\\d{1,4})\$#", "%010d/%04d");
             }
         default:
             // not implemented
             return FALSE;
     }
 }