/** * @param mixed $iswc * * @return bool */ public static function validate($iswc) { if (!(bool) preg_match('/^\\s*T[\\-.]?(\\d)(\\d)(\\d)[\\-.]?(\\d)(\\d)(\\d)[\\-.]?(\\d)(\\d)(\\d)[\\-.]?(\\d)\\s*$/i', $iswc)) { return false; } $hyphens = ['‐', '-', '.']; $iswc = parent::unDecorate($iswc, $hyphens); $sum = 1; for ($i = 1; $i <= 9; ++$i) { $sum = $sum + $i * (int) $iswc[$i]; } $rem = $sum % 10; if ($rem !== 0) { $rem = 10 - $rem; } return (int) $iswc[10] === $rem; }
/** * {@inheritdoc} */ public static function unDecorate($gtin, $hyphens = self::HYPHENS) { return parent::unDecorate($gtin, $hyphens); }