You are here

function isbn_field_validate in ISBN Field 7

Implements hook_field_validate().

File

./isbn.module, line 26
Maintains a consistant relationship between nodes and ISBNs.

Code

function isbn_field_validate($obj_type, $object, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    $isbn = isbn_clean_data($item['isbn']);
    if ($isbn != '' && !isbn_check_10($isbn) && !isbn_check_13($isbn)) {
      if (strlen($isbn) < 10 && strlen($isbn) > 13) {
        $message = t('"%isbn" isn\'t a valid ISBN number. A valid ISBN number has 10 or 13 digits.', array(
          '%isbn' => $isbn,
        ));
      }
      else {
        if (strlen($isbn) == 10 && !isbn_check_10($isbn)) {
          $message = t('"%isbn" isn\'t a valid 10 digit ISBN number.', array(
            '%isbn' => $isbn,
          ));
        }
        if (strlen($isbn) == 13 && !isbn_check_13($isbn)) {
          $message = t('"%isbn" isn\'t a valid 13 digit ISBN number.', array(
            '%isbn' => $isbn,
          ));
        }
      }
      $errors[$field['field_name']][$langcode][$delta][] = array(
        'error' => "isbn_invalid",
        'message' => $message,
      );
    }
  }
}