25 #require_once 'Zend/Validate/Abstract.php'; 47 self::INVALID =>
"Invalid type given. String or integer expected",
48 self::NO_ISBN =>
"'%value%' is not a valid ISBN number",
81 #require_once 'Zend/Validate/Exception.php'; 86 if (array_key_exists(
'type',
$options)) {
91 if (array_key_exists(
'separator',
$options)) {
104 $sep = quotemeta($this->_separator);
109 if ($this->_type == self::ISBN10 || $this->_type == self::AUTO) {
114 $pattern =
"/^[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9X]{1}$/";
123 if ($this->_type == self::ISBN13 || $this->_type == self::AUTO) {
128 $pattern =
"/^[0-9]{1,9}[{$sep}]{1}[0-9]{1,5}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1}$/";
138 if ((strlen($this->_value) == $lengths[
$pattern]) && preg_match(
$pattern, $this->_value)) {
157 $this->
_error(self::INVALID);
167 $isbn10 = str_replace($this->_separator,
'',
$value);
169 for (
$i = 0;
$i < 9;
$i++) {
170 $sum += (10 -
$i) * $isbn10{
$i};
174 $checksum = 11 - ($sum % 11);
175 if ($checksum == 11) {
177 }
elseif ($checksum == 10) {
184 $isbn13 = str_replace($this->_separator,
'',
$value);
186 for (
$i = 0;
$i < 12;
$i++) {
190 $sum += 3 * $isbn13{
$i};
194 $checksum = 10 - ($sum % 10);
195 if ($checksum == 10) {
201 $this->
_error(self::NO_ISBN);
206 if (substr($this->_value, -1) != $checksum) {
207 $this->
_error(self::NO_ISBN);
225 if (!in_array($separator, array(
'-',
' ',
''))) {
229 #require_once 'Zend/Validate/Exception.php'; 233 $this->_separator = $separator;
257 if (!in_array(
$type, array(self::AUTO, self::ISBN10, self::ISBN13))) {
261 #require_once 'Zend/Validate/Exception.php'; 265 $this->_type =
$type;
elseif(isset( $params[ 'redirect_parent']))
_error($messageKey, $value=null)
__construct($options=array())