/** * 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."); } } } } } }
/** * Validate a SSCC (Serial Shipping Container Code) * * This function checks given SSCC number * used to identify logistic units. * http://www.ean-ucc.org/ * http://www.uc-council.org/checkdig.htm * * @param string $sscc number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @access public * @see Validate_ISPN::process() * @author Piotr Klaban <*****@*****.**> */ function sscc($sscc) { static $weights_sscc = array(3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3); return Validate_ISPN::process($sscc, 18, $weights_sscc, 10, 10); }