/** * Checks whether $isbn matches the ISBN-13 format. * * @param string $isbn * @return boolean * @throws Exception */ public function is13($isbn) { if (is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } $isbn = $this->hyphens->removeHyphens($isbn); return strlen($isbn) === 13; }
/** * Validate the ISBN-13 $isbn * * @param string $isbn * @return boolean * @throws Exception */ public function isbn13($isbn) { if (is_string($isbn) === false) { throw new Exception('Invalid parameter type.'); } //Verify ISBN-13 scheme $isbn = $this->hyphens->removeHyphens($isbn); if (strlen($isbn) != 13) { return false; } if (preg_match('/\\d{13}/i', $isbn) == false) { return false; } //Verify checksum $check = 0; for ($i = 0; $i < 13; $i += 2) { $check += substr($isbn, $i, 1); } for ($i = 1; $i < 12; $i += 2) { $check += 3 * substr($isbn, $i, 1); } return $check % 10 === 0; }