View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Validate_BankAccount_Be
{zone-data}

{zone-data:proposer-list}
[Andries Seutens|mailto:andries.seutens@skynet.be]
{zone-data}

{zone-data:revision}
1.0 - 4 February 2008: Updated from community comments.
{zone-data}

{zone-data:overview}
Zend_Validate_BankAccount_Be will validate the format of a Belgian bank account
{zone-data}

{zone-data:references}
{zone-data}

{zone-data:requirements}
{zone-data}

{zone-data:dependencies}
{zone-data}

{zone-data:operation}
{zone-data}

{zone-data:milestones}
{zone-data}

{zone-data:class-list}
{zone-data}

{zone-data:use-cases}
{zone-data}

{zone-data:skeletons}
{code:php}
<?php

/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/


/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';


/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Validate_BankAccount_Be extends Zend_Validate_Abstract
{
const FORMAT = 'formatMismatch';
const CHECK_DIGIT = 'checkDigit';

/**
* @var array
*/
protected $_messageTemplates = array(
self::FORMAT => "'%value%' has an invalid format",
self::CHECK_DIGIT => "'%value%' check digit mismatch",
);

/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid Belgian bank transfer message
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
// 1-3 number for the bank socity, 4-10 number for the account, 11-12 check digit
if ((bool) ereg('^[0-9]{3}[ ./-]?[0-9]{4}[ ./-]?[0-9]{5}$', $value)) {
$bankTransferMessage = preg_replace('/[Zend_Font - Karol Babioch^0-9]/', '', $value);

list($number, $checkDigit) = sscanf($bankTransferMessage, '%10d%2d');
if ($checkDigit == fmod($number, 97)) {
return true;
} else {
$this->_error(self::CHECK_DIGIT);
return false;
}
} else {
$this->_error(self::FORMAT);
return false;
}
}
}

{code}
{zone-data}
{zone-template-instance}]]></ac:plain-text-body></ac:macro>