ISIN check

Wikipedia, Stichwort "International Securities Identification Number", Version vom 11. Oktober 2009 um 23:39 Uhr, abrufbar unter de.wikipedia.org:

Check a ISIN

Either you submit a 12 character ISIN to check it is valid or you submit a 11 character ISIN to calculate the checksum.

ISIN: 

PHP sourcecode

       /**
        * @return int 0 if checksum correct, int other from 0 if checksum incorrect
        * else int checksum (the 12th char for $src) if $src length == 11
        */
       public static function calculateCheckISIN($src)
       {
               $result = 0;
               $whatLength = (strlen($src) == 12)? 1 : 2;
               for($i = strlen($src) - 1; $i >= 0; $i--)
               {
                       $current = intval(ord(substr($src, $i, 1)));
                       if($current > ord('9'))
                       {
                               // It is a char
                               $current -= intval((ord('A') - 10));
                               $result += intval((3 - $whatLength)*intval($current/10) + $whatLength*$current + ($whatLength-1)*intval(($current%10)/5));
                       }
                       else
                       {
                               // It is a numeric character
                               $current -= intval(ord('0'));
                               $result += intval($whatLength*$current + ($whatLength-1)*intval($current/5));
                               $whatLength = intval(3 - $whatLength);
                       }
               }
               $result %= 10;
               $result = ((10 - $result%10) % 10);
               return $result;
       }

Have a look at the Java implementation.