diff --git a/README.md b/README.md index df9a5dd..77792d1 100644 --- a/README.md +++ b/README.md @@ -319,10 +319,8 @@ Your Help Wanted * If you know the URL of __national IBAN, BBAN or national checksum documentation__ from official sources, please let us know at [issue #39](https://github.com/globalcitizen/php-iban/issues/39) and [issue #41](https://github.com/globalcitizen/php-iban/issues/41). * __Faroe Islands__ (FO) banks do not respond, neither does the Danish National Bank who referred me to them. - * __Italy__ (IT) has a custom checksum system we need some help deciphering. Note that it is not the [Italian fiscal code](https://en.wikipedia.org/wiki/Italian_fiscal_code_card). * __Luxembourg__ (LU) does not seem to conform to any single checksum system. While some IBAN do validate with reasonably common systems, others don't or use others. The suggestion that Luxembourg has a national checksum system may in fact be incorrect. We need some clarification here, hopefully someone can dig up an official statement. * __Mauritania__ (MR) has a dual character checksum system but our example IBAN does not match MOD97-10 which would be the expected system. Previously the IBAN here was always fixed to '13' checksum digits, however as of registry v66 it is now dynamic, which suggests a changed or at least now nationally relaxed checksum system. - * __San Marino__ (SM) has an alphabetic checksum with an unknown algorithm. * If you are willing to spend some time searching, we could do with some more test IBANs for most countries, especially smaller ones... diff --git a/php-iban.php b/php-iban.php index 9903708..e9d8959 100644 --- a/php-iban.php +++ b/php-iban.php @@ -1227,13 +1227,21 @@ function _iban_nationalchecksum_implementation_it($iban,$mode) { } } -# Italian checksum +# Implement the national checksum for a San Marino (SM) IBAN +function _iban_nationalchecksum_implementation_sm($iban,$mode) { + // San Marino adheres to Italian rules. + return _iban_nationalchecksum_implementation_it($iban,$mode); +} + +# Italian (and San Marino's) checksum # (Credit: Translated by Francesco Zanoni from http://community.visual-basic.it/lucianob/archive/2004/12/26/2464.aspx) +# (Source: European Commettee of Banking Standards' Register of European Account Numbers (TR201 V3.23 — FEBRUARY 2007), +# available at URL http://www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf) function _italian($input) { $digits = str_split('0123456789'); $letters = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ-. '); - $bbanWithoutChecksumLength = 22; + $lengthOfBbanWithoutChecksum = 22; $divisor = 26; $evenList = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28); $oddList = array(1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23, 27, 28, 26); @@ -1241,7 +1249,7 @@ function _italian($input) // Character value computation $sum = 0; - for ($k = 0; $k < $bbanWithoutChecksumLength; $k++) { + for ($k = 0; $k < $lengthOfBbanWithoutChecksum; $k++) { $i = array_search($input[$k], $digits); if ($i === false) {