You are here

function isbn_check_10 in ISBN Field 7

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

Check if the ISBN number is a valid 10 digit.

Parameters

$isbn: The ISBN number with only valid characters.

Return value

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

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

File

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

Code

function isbn_check_10($isbn) {
  if (strlen($isbn) < 10) {
    return FALSE;
  }
  $check = 0;
  for ($i = 0; $i < 9; $i++) {
    $check += (10 - $i) * $isbn[$i];
  }
  $tenth = $isbn[9];

  // tenth digit (aka checksum or check digit)
  $check += strtoupper($tenth) == 'X' ? 10 : $tenth;
  return $check % 11 == 0;
}