예제 #1
0
function verify_iban($iban)
{
    # First convert to machine format.
    $iban = iban_to_machine_format($iban);
    # Get country of IBAN
    $country = iban_get_country_part($iban);
    # Test length of IBAN
    if (strlen($iban) != iban_country_get_iban_length($country)) {
        return false;
    }
    # Get checksum of IBAN
    $checksum = iban_get_checksum_part($iban);
    # Get country-specific IBAN format regex
    $regex = '/' . iban_country_get_iban_format_regex($country) . '/';
    # Check regex
    if (preg_match($regex, $iban)) {
        # Regex passed, check checksum
        if (!iban_verify_checksum($iban)) {
            return false;
        }
    } else {
        return false;
    }
    # Otherwise it 'could' exist
    return true;
}
예제 #2
0
    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)) {
                print " (does not match regex {$regex} for country {$country})";
            }
            ####################################################
            $errors++;
            $suggestions = iban_mistranscription_suggestions($iban);
            if (is_array($suggestions)) {
예제 #3
0
    #$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";
        $correct = iban_set_checksum($iban);
        if ($correct == $iban) {
            print "       (checksum is correct, structure must have issues.)\n";
            $machine_iban = iban_to_machine_format($iban);
            print "        (machine format is: '{$machine_iban}')\n";
            $country = iban_get_country_part($machine_iban);
            print "        (country is: '{$country}')\n";
            if (strlen($machine_iban) != iban_country_get_iban_length($country)) {
                print "        (ERROR: length of '" . strlen($machine_iban) . "' does not match expected length for country's IBAN '" . iban_country_get_iban_length($country) . "'.)";
            }
            $regex = '/' . iban_country_get_iban_format_regex($country) . '/';
            if (!preg_match($regex, $machine_iban)) {
                print "        (ERROR: did not match regular expression '" . $regex . "')\n";
            }
        } else {
            print "       (correct checksum version would be '" . $correct . "')\n";
        }
        $errors++;
        exit(1);
    }
    print "\n";
}
exit($errors);
예제 #4
0
 public function IBANLength()
 {
     return iban_country_get_iban_length($this->code);
 }
예제 #5
0
function _iban_nationalchecksum_implementation($iban, $mode)
{
    if ($mode != 'set' && $mode != 'find' && $mode != 'verify') {
        return '';
    }
    #  blank value on return to distinguish from correct execution
    $iban = iban_to_machine_format($iban);
    $country = iban_get_country_part($iban);
    if (strlen($iban) != iban_country_get_iban_length($country)) {
        return '';
    }
    $function_name = '_iban_nationalchecksum_implementation_' . strtolower($country);
    if (function_exists($function_name)) {
        return $function_name($iban, $mode);
    }
    return '';
}