cvs: pear /Validate Validate.php
| From: | Pierre-Alain Joye | Date: | Wed, 10 Dec 2003 15:06:24 +0000 |
| Subject: | cvs: pear /Validate Validate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14758@lists.php.net to get a copy of this message | ||
pajoye Wed Dec 10 10:06:24 2003 EDT
Modified files:
/pear/Validate Validate.php
Log:
- Add EAN8 method
Index: pear/Validate/Validate.php
diff -u pear/Validate/Validate.php:1.36 pear/Validate/Validate.php:1.37
--- pear/Validate/Validate.php:1.36 Tue Dec 9 10:42:38 2003
+++ pear/Validate/Validate.php Wed Dec 10 10:06:24 2003
@@ -5,10 +5,10 @@
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license, |
+// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
-// | available at through the world-wide-web at |
-// | http://www.php.net/license/2_02.txt.
|
+// | available through the world-wide-web at the following url: |
+// | http://www.php.net/license/3_0.txt.
|
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
@@ -17,7 +17,7 @@
// | Pierre-Alain Joye <paj@pearfr.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Validate.php,v 1.36 2003/12/09 15:42:38 pajoye Exp $
+// $Id: Validate.php,v 1.37 2003/12/10 15:06:24 pajoye Exp $
//
// Methods for common data validations
//
@@ -188,7 +188,6 @@
function creditCard($creditCard)
{
$creditCard = preg_replace('/[^0-9]/','',$creditCard);
-
if (empty($creditCard) || ($len_number = strlen($creditCard)) <= 0) {
return false;
}
@@ -438,6 +437,33 @@
return Validate::_check_control_number($ismn, $weights_ismn, 10, 10);
}
+
+ /**
+ * Validate a EAN/UCC-8 number
+ *
+ * This function checks given EAN8 number
+ * used to identify trade items and special applications.
+ * http://www.ean-ucc.org/
+ * http://www.uc-council.org/checkdig.htm
+ *
+ * @param string $ean number (only numeric chars will be considered)
+ * @return bool true if number is valid, otherwise false
+ * @author Piotr Klaban <makler@man.torun.pl>
+ */
+ function ean8($ean)
+ {
+ static $weights_ean8 = array(3,1,3,1,3,1,3);
+
+ $ean = str_replace(array('-','/','
',"\t","\n"), '', $ean);
+
+ // check if this is a 8-digit number
+ if (!is_numeric($ean) || strlen($ean) != 8) {
+ return false;
+ }
+
+ return Validate::_check_control_number($ean, $weights_ean8, 10, 10);
+ }
+
/**
* Validate a EAN/UCC-13 number
*