You are here

function _isbn_validate_13 in ISBN Field 6

Validator for 13 digit ISBNs from http://www.alixaxel.com/wordpress/wp-content/2007/07/ISBN.php

1 call to _isbn_validate_13()
isbn_validate_13 in ./isbn.module

File

./isbn.module, line 91
Defines ISBN field types.

Code

function _isbn_validate_13($string) {
  settype($string, 'string');
  if (strlen($string) != 13) {
    return false;
  }
  $stack = 0;
  $even = false;
  for ($i = 12; $i >= 0; $i--) {
    if ($even === true) {
      $stack += $string[$i] * 3;
      $even = false;
    }
    else {
      $stack += $string[$i];
      $even = true;
    }
  }
  if ($stack % 10 == 0) {
    return true;
  }
  return false;
}