cvs: pear /Validate/Validate FR.php
| From: | Pierre-Alain Joye | Date: | Sun, 16 Feb 2003 17:21:34 +0000 |
| Subject: | cvs: pear /Validate/Validate FR.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8886@lists.php.net to get a copy of this message | ||
pajoye Sun Feb 16 12:21:34 2003 EDT
Modified files:
/pear/Validate/Validate FR.php
Log:
Add rib, siret, siren checks
Index: pear/Validate/Validate/FR.php
diff -u pear/Validate/Validate/FR.php:1.3 pear/Validate/Validate/FR.php:1.4
--- pear/Validate/Validate/FR.php:1.3 Sat Jan 4 06:56:29 2003
+++ pear/Validate/Validate/FR.php Sun Feb 16 12:21:34 2003
@@ -18,7 +18,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: FR.php,v 1.3 2003/01/04 11:56:29 mj Exp $
+// $Id: FR.php,v 1.4 2003/02/16 17:21:34 pajoye Exp $
//
// Specific validation methods for data used in France
//
@@ -112,6 +112,9 @@
*/
function rib($aCodeBanque, $aCodeGuichet, $aNoCompte, $aKey)
{
+ if(is_array($aCodeBanque)) {
+ extract($aCodeBanque);
+ }
$chars =
array('/[AJ]/','/[BKZ]/','/[CLT]/','/[DMU]/','/[ENV]/','/[FOW]/','/[GPX]/','/[HQY]/','/[IRZ]/');
$values =
array('1','2','3','4','5','6','7','8','9');
@@ -144,5 +147,87 @@
}
return $key==$aKey;
}
+
+
+ /**
+ * Validate a french SIREN number
+ *
+ *
+ * @param string $siren number or an array containaing the 'number'=>1234
+ * @return bool true if number is valid, otherwise false
+ * @author Damien Seguy, added by Pierre-Alain Joye <paj@pearfr.org>
+ */
+ function siren($siren)
+ {
+ if( is_array($siren) ) {
+ extract( $number );
+ }
+ $siren = str_replace(' ', '', $siren);
+ if (!preg_match("/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)$/",
+ $siren, $match)) {
+ return false;
+ } else {
+ $match[2] *= 2;
+ $match[4] *= 2;
+ $match[6] *= 2;
+ $match[8] *= 2;
+ $somme = 0;
+
+ for ($i = 1; $i<count($match); $i++) {
+ if ($match[$i] > 9) {
+ $a = (int)substr($match[$i], 0, 1);
+ $b = (int)substr($match[$i], 1, 1);
+ $match[$i] = $a + $b;
+ }
+ $somme += $match[$i];
+ }
+ return (($somme % 10) == 0);
+ }
+
+ /**
+ * Validate a french SIRET number
+ *
+ *
+ * @param string $siret number or an array containaing the 'number'=>1234
+ * @return bool true if number is valid, otherwise false
+ * @author Damien Seguy, added by Pierre-Alain Joye <paj@pearfr.org>
+ */
+ function siret($siret)
+ {
+ $siret = str_replace(' ', '', $siret);
+ if (
+ !preg_match(
+ "/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)$/",
+ $siret, $match
+ )
+ ) {
+ return false;
+ } else {
+ if( !Validate_FR::siren(implode('', array_slice($match, 1,9))) ) {
+ return false;
+ }
+ }
+ $match[1] *= 2;
+ $match[3] *= 2;
+ $match[5] *= 2;
+ $match[7] *= 2;
+ $match[9] *= 2;
+ $match[11] *= 2;
+ $match[13] *= 2;
+
+ $somme = 0;
+
+ for ($i = 1; $i<count($match); $i++) {
+ if ($match[$i] > 9) {
+ $a = (int)substr($match[$i], 0, 1);
+ $b = (int)substr($match[$i], 1, 1);
+ $match[$i] = $a + $b;
+ }
+ $somme += $match[$i];
+ }
+
+ return ( ($somme % 10) == 0 )
+
+ }
}
?>