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_Ssn_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_Ssn_Be will validate the format of a Belgian ssn (SIS)
{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_Ssn_Be extends Zend_Validate_Abstract
{
const FORMAT = 'formatMismatch';
const CHECK_DIGIT = 'checkDigit';

/**
* @var array
*/
protected $_messageTemplates = array(
self::FORMAT => "'%value%' should consist of 11 digits",
self::CHECK_DIGIT => "'%value%' check digit mismatch",
);

/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid Belgian social security number
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
// check 1: consists of 11 digits
if (!(bool) ereg('^[0-9]{11}$', $value)) {
$this->_error(self::FORMAT);
return false;
}

// 1-6 = birthday (jjmmdd), 7-9 = day count number, 10-11 = check digit
list($number, $checkDigit) = sscanf($value, '%9d%2d');

// check 2: born before 2000/01/01
if ((97 - fmod($number, 97)) == $checkDigit) {
return true;
}

// check 3: born after 1999/12/31 (add 2000000000)
$number += 2000000000;
if ((97 - fmod($number, 97)) == $checkDigit) {
return true;
}

$this->_error(self::CHECK_DIGIT);
return false;
}
}

{code}
{zone-data}

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