| version 1.1, 2005/06/05 12:14:44 |
version 1.2, 2005/11/25 09:49:58 |
|
|
| <?php |
<?php |
| /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
| // +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| // | PHP Version 4 | |
// | Copyright (c) 1997-2005 Stefan Neufeind | |
| // +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| // | Copyright (c) 1997-2003 The PHP Group | |
// | This source file is subject to the New BSD license, That is bundled | |
| // +----------------------------------------------------------------------+ |
// | with this package in the file LICENSE, and is available through | |
| // | This source file is subject to version 3.0 of the PHP license, | |
// | the world-wide-web at | |
| // | that is bundled with this package in the file LICENSE, and is | |
// | http://www.opensource.org/licenses/bsd-license.php | |
| // | available through the world-wide-web at the following url: | |
// | If you did not receive a copy of the new BSDlicense and are unable | |
| // | http://www.php.net/license/3_0.txt. | |
// | to obtain it through the world-wide-web, please send a note to | |
| // | If you did not receive a copy of the PHP license and are unable to | |
// | pajoye@php.net so we can mail you a copy immediately. | |
| // | obtain it through the world-wide-web, please send a note to | |
|
| // | license@php.net so we can mail you a copy immediately. | |
|
| // +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| // | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> | |
// | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> | |
| // +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| // |
// |
| // $Id$ |
/** |
| |
* Methods for common data validations |
| |
* |
| |
* @category Validate |
| |
* @package Validate_Finance_IBAN |
| |
* @author Stefan Neufeind <pear.neufeind@speedpartner.de> |
| |
* @copyright 2005 The PHP Group |
| |
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| |
* @version CVS: $Id$ |
| |
* @link http://pear.php.net/package/Validate_Finance_IBAN |
| |
*/ |
| |
|
| |
|
| /* |
/* |
| * Error codes for the IBAN interface, which will be mapped to textual messages |
* Error codes for the IBAN interface, which will be mapped to textual messages |
| Line 34 define('VALIDATE_FINANCE_IBAN_INVALID_FO |
|
| Line 43 define('VALIDATE_FINANCE_IBAN_INVALID_FO |
|
| define('VALIDATE_FINANCE_IBAN_CHECKSUM_INVALID', -8); |
define('VALIDATE_FINANCE_IBAN_CHECKSUM_INVALID', -8); |
| |
|
| /** |
/** |
| * Validate and process IBAN (international bank account numbers) |
* Validate and process IBAN (international bank account numbers) |
| * |
* |
| * @author Stefan Neufeind <neufeind@speedpartner.de> |
* @category Validate |
| */ |
* @package Validate_Finance_IBAN |
| class Validate_Finance_IBAN { |
* @author Stefan Neufeind <neufeind@speedpartner.de> |
| |
* @copyright 2005 The PHP Group |
| |
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| |
* @version Release: @package_version@ |
| |
* @link http://pear.php.net/package/Validate |
| |
*/ |
| |
class Validate_Finance_IBAN |
| |
{ |
| /** |
/** |
| * String containing the IBAN to be processed |
* String containing the IBAN to be processed |
| * @var string |
* @var string |
| Line 52 class Validate_Finance_IBAN { |
|
| Line 68 class Validate_Finance_IBAN { |
|
| * @access private |
* @access private |
| */ |
*/ |
| var $_errorcode = 0; |
var $_errorcode = 0; |
| |
|
| /** |
/** |
| * List of all IBAN countrycodes; also gives corresponding countrynames (in long form) |
* List of all IBAN countrycodes; also gives corresponding countrynames (in long form) |
| * @return array |
* @return array |
| Line 79 class Validate_Finance_IBAN { |
|
| Line 95 class Validate_Finance_IBAN { |
|
| 'GR' => 'Greece', |
'GR' => 'Greece', |
| 'HU' => 'Hungary', |
'HU' => 'Hungary', |
| 'IE' => 'Ireland', |
'IE' => 'Ireland', |
| 'IS' => 'Island', |
'IS' => 'Iceland', |
| 'IT' => 'Italy', |
'IT' => 'Italy', |
| 'LU' => 'Luxembourg', |
'LU' => 'Luxembourg', |
| 'NL' => 'The Netherlands', |
'NL' => 'The Netherlands', |
| Line 88 class Validate_Finance_IBAN { |
|
| Line 104 class Validate_Finance_IBAN { |
|
| 'PT' => 'Portugal', |
'PT' => 'Portugal', |
| 'SE' => 'Sweden', |
'SE' => 'Sweden', |
| 'SI' => 'Slovenia' |
'SI' => 'Slovenia' |
| ); |
); |
| } |
} |
| return $_iban_countrycode_countryname; |
return $_iban_countrycode_countryname; |
| } |
} |
| Line 258 class Validate_Finance_IBAN { |
|
| Line 274 class Validate_Finance_IBAN { |
|
| * @param string $iban IBAN to be validated / processed |
* @param string $iban IBAN to be validated / processed |
| * @access public |
* @access public |
| */ |
*/ |
| function Validate_Finance_IBAN($iban='') |
function Validate_Finance_IBAN($iban = '') |
| { |
{ |
| $iban = strtoupper($iban); |
$iban = strtoupper($iban); |
| $this->_iban = $iban; |
$this->_iban = $iban; |
| } // end constructor |
} // end constructor |
| |
|
| /** |
/** |
| * Returns the current API version |
|
| * |
|
| * @access public |
|
| * @return float |
|
| */ |
|
| function apiVersion() |
|
| { |
|
| return 1.0; |
|
| } // end func apiVersion |
|
| |
|
| /** |
|
| * Returns the current IBAN |
* Returns the current IBAN |
| * |
* |
| * @access public |
* @access public |
| Line 293 class Validate_Finance_IBAN { |
|
| Line 298 class Validate_Finance_IBAN { |
|
| * @access public |
* @access public |
| * @return void |
* @return void |
| */ |
*/ |
| function setIBAN($iban='') |
function setIBAN($iban = '') |
| { |
{ |
| $iban = strtoupper($iban); |
$iban = strtoupper($iban); |
| $this->_iban = $iban; |
$this->_iban = $iban; |
| Line 306 class Validate_Finance_IBAN { |
|
| Line 311 class Validate_Finance_IBAN { |
|
| * @access public |
* @access public |
| * @return boolean true if no error found |
* @return boolean true if no error found |
| */ |
*/ |
| function validate($arg=null) |
function validate($arg = null) |
| { |
{ |
| if ( isset($this) && is_a($this, 'Validate_Finance_IBAN') ) { |
if ( isset($this) && is_a($this, 'Validate_Finance_IBAN') ) { |
| $iban = $this->_iban; |
$iban = $this->_iban; |
| Line 328 class Validate_Finance_IBAN { |
|
| Line 333 class Validate_Finance_IBAN { |
|
| if (!isset($_iban_countrycode_regex)) { |
if (!isset($_iban_countrycode_regex)) { |
| $_iban_countrycode_regex = Validate_Finance_IBAN::_getCountrycodeRegex(); |
$_iban_countrycode_regex = Validate_Finance_IBAN::_getCountrycodeRegex(); |
| } |
} |
| |
|
| if (strlen($iban) <= 4) { |
if (strlen($iban) <= 4) { |
| $errorcode = VALIDATE_FINANCE_IBAN_TOO_SHORT; |
$errorcode = VALIDATE_FINANCE_IBAN_TOO_SHORT; |
| } elseif (!isset( $_iban_countrycode_countryname[ substr($iban,0,2) ] )) { |
} elseif (!isset( $_iban_countrycode_countryname[ substr($iban,0,2) ] )) { |
| Line 366 class Validate_Finance_IBAN { |
|
| Line 371 class Validate_Finance_IBAN { |
|
| } |
} |
| } |
} |
| |
|
| if ( isset($this) ) { |
if (isset($this)) { |
| $this->_errorcode=$errorcode; |
$this->_errorcode=$errorcode; |
| } |
} |
| return ($errorcode == VALIDATE_FINANCE_IBAN_OK); |
return ($errorcode == VALIDATE_FINANCE_IBAN_OK); |