protected function IsbnValidator::validateIsbn10 in Plug 7
1 call to IsbnValidator::validateIsbn10()
- IsbnValidator::validate in lib/Symfony/validator/Symfony/Component/Validator/Constraints/IsbnValidator.php
- Checks if the passed value is valid.
File
- lib/Symfony/validator/Symfony/Component/Validator/Constraints/IsbnValidator.php, line 105
Class
- IsbnValidator
- Validates whether the value is a valid ISBN-10 or ISBN-13
Namespace
Symfony\Component\Validator\Constraints
Code
protected function validateIsbn10($isbn) {
$checkSum = 0;
for ($i = 0; $i < 10; ++$i) {
if (!isset($isbn[$i])) {
return Isbn::TOO_SHORT_ERROR;
}
if ('X' === $isbn[$i]) {
$digit = 10;
}
elseif (ctype_digit($isbn[$i])) {
$digit = $isbn[$i];
}
else {
return Isbn::INVALID_CHARACTERS_ERROR;
}
$checkSum += $digit * (10 - $i);
}
if (isset($isbn[$i])) {
return Isbn::TOO_LONG_ERROR;
}
return 0 === $checkSum % 11 ? true : Isbn::CHECKSUM_FAILED_ERROR;
}