Esempio n. 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;
}
Esempio n. 2
0
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)) {
                if (count($suggestions) == 1) {
                    print " (you meant '" . $suggestions[0] . "', right?)";
                } elseif (count($suggestions) > 1) {
                    print " (perhaps ";
                    $done = 0;
Esempio n. 3
0
 public function VerifyChecksum()
 {
     return iban_verify_checksum($this->iban);
 }