cvs: pear /Validate/Validate ISPN.php
| From: | Piotr Klaban | Date: | Tue, 08 Nov 2005 08:17:22 +0000 |
| Subject: | cvs: pear /Validate/Validate ISPN.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36149@lists.php.net to get a copy of this message | ||
makler Tue Nov 8 03:17:22 2005 EDT
Modified files:
/pear/Validate/Validate ISPN.php
Log:
isbn() wrapper, isbn13() function created. Fixed wrong check for ISBN format in isbn10()
http://cvs.php.net/diff.php/pear/Validate/Validate/ISPN.php?r1=1.9&r2=1.10&ty=u
Index: pear/Validate/Validate/ISPN.php
diff -u pear/Validate/Validate/ISPN.php:1.9 pear/Validate/Validate/ISPN.php:1.10
--- pear/Validate/Validate/ISPN.php:1.9 Tue Nov 1 08:12:30 2005
+++ pear/Validate/Validate/ISPN.php Tue Nov 8 03:17:19 2005
@@ -27,7 +27,7 @@
* @copyright 1997-2005 Piotr Klaban, Damien Seguy, Helgi Þormar Þorbjörnsson,
* Pierre-Alain Joye
* @license http://www.opensource.org/licenses/bsd-license.php
new BSD
- * @version CVS: $Id: ISPN.php,v 1.9 2005/11/01 13:12:30 pajoye Exp $
+ * @version CVS: $Id: ISPN.php,v 1.10 2005/11/08 08:17:19 makler Exp $
* @link http://pear.php.net/package/Validate_ISPN
*/
@@ -59,7 +59,23 @@
{
function isbn($isbn)
{
+ if (preg_match("/[^0-9 IXSBN-]/", $isbn)) {
+ return false;
+ }
+
+ $isbn = strtoupper($isbn);
+ $isbn = str_replace(array('ISBN', '-', ' ', "\t",
"\n"), '', $isbn);
+ if (strlen($isbn) != 10) {
+ return false;
+ }
+ if (strlen($isbn) == 13) {
+ return Validate_ISPN::isbn13($isbn);
+ } elseif (strlen($isbn) == 10) {
+ return Validate_ISPN::isbn10($isbn);
+ } else {
+ return false;
+ }
}
/**
@@ -75,10 +91,21 @@
* @return bool true if number is valid, otherwise false
* @access public
* @author Helgi Þormar <dufuz@php.net>
+ * @author Piotr Klaban <makler@man.torun.pl>
*/
function isbn13($isbn)
{
+ if (preg_match("/[^0-9 ISBN-]/", $isbn)) {
+ return false;
+ }
+
+ $isbn = strtoupper($isbn);
+ $isbn = str_replace(array('ISBN', '-', ' ', "\t",
"\n"), '', $isbn);
+ if (!preg_match('/^[0-9]{13}$/', $isbn)) {
+ return false;
+ }
+ return Validate_ISPN::ean13($isbn);
}
/**
@@ -110,7 +137,7 @@
return false;
}
- if (preg_match("/[^0-9]{9}[^0-9X]/", $isbn)) {
+ if (!preg_match('/^[0-9]{9}[0-9X]$/', $isbn)) {
return false;
}
@@ -321,4 +348,4 @@
return Validate::_checkControlNumber($data, $weights, $modulo, $subtract);
}
}
-?>
\ No newline at end of file
+?>