function isbn($isbn) { if (preg_match("/[^0-9 IXSBN-]/", $isbn)) { return false; } $isbn = strtoupper($isbn); $isbn = str_replace(array('ISBN', '-', ' ', "\t", "\n"), '', $isbn); if (strlen($isbn) == 13) { return Validate_ISPN::isbn13($isbn); } elseif (strlen($isbn) == 10) { return Validate_ISPN::isbn10($isbn); } return false; }
/** * Looks at 020$a and reports errors if the check digit is wrong. * Looks at 020$z and validates number if hyphens are present. * * @param File_MARC_Field $field Field to check * * @return void */ protected function check020($field) { foreach ($field->getSubfields() as $current) { $data = $current->getData(); // remove any hyphens $isbn = str_replace('-', '', $data); // remove nondigits $isbn = preg_replace('/^\\D*(\\d{9,12}[X\\d])\\b.*$/', '$1', $isbn); if ($current->getCode() == 'a') { if (substr($data, 0, strlen($isbn)) != $isbn) { $this->warn("020: Subfield a may have invalid characters."); } // report error if no space precedes a qualifier in subfield a if (preg_match('/\\(/', $data) && !preg_match('/[X0-9] \\(/', $data)) { $this->warn("020: Subfield a qualifier must be preceded by space, {$data}."); } // report error if unable to find 10-13 digit string of digits in // subfield 'a' if (!preg_match('/(?:^\\d{10}$)|(?:^\\d{13}$)|(?:^\\d{9}X$)/', $isbn)) { $this->warn("020: Subfield a has the wrong number of digits, {$data}."); } else { if (strlen($isbn) == 10) { if (!Validate_ISPN::isbn10($isbn)) { $this->warn("020: Subfield a has bad checksum, {$data}."); } } else { if (strlen($isbn) == 13) { if (!Validate_ISPN::isbn13($isbn)) { $this->warn("020: Subfield a has bad checksum (13 digit), {$data}."); } } } } } else { if ($current->getCode() == 'z') { // look for valid isbn in 020$z if (preg_match('/^ISBN/', $data) || preg_match('/^\\d*\\-\\d+/', $data)) { // ################################################## // ## Turned on for now--Comment to unimplement #### // ################################################## if (strlen($isbn) == 10 && Validate_ISPN::isbn10($isbn) == 1) { $this->warn("020: Subfield z is numerically valid."); } } } } } }