You are here

function isbn_check_13 in ISBN Field 7

Same name and namespace in other branches
  1. 6.0 isbn.module \isbn_check_13()

Check if the ISBN number is a valid 13 digit.

Parameters

$isbn: The ISBN number with only valid characters.

Return value

True if it's a valid 13 digit ISBN number, false otherwise.

1 call to isbn_check_13()
isbn_field_validate in ./isbn.module
Implements hook_field_validate().

File

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

Code

function isbn_check_13($isbn) {
  if (strlen($isbn) < 13) {
    return FALSE;
  }
  $check = 0;
  for ($i = 0; $i < 13; $i += 2) {
    $check += $isbn[$i];
  }
  for ($i = 1; $i < 12; $i += 2) {
    $check += 3 * $isbn[$i];
  }
  return $check % 10 == 0;
}