Validate_NL
[ class tree: Validate_NL ] [ index: Validate_NL ] [ all elements ]

Source for file NL.php

Documentation is available at NL.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4.  * Specific validation methods for data used in the Netherlands
  5.  *
  6.  * PHP Versions 4 and 5
  7.  *
  8.  * This source file is subject to the New BSD license, That is bundled
  9.  * with this package in the file LICENSE, and is available through
  10.  * the world-wide-web at
  11.  * http://www.opensource.org/licenses/bsd-license.php
  12.  * If you did not receive a copy of the new BSDlicense and are unable
  13.  * to obtain it through the world-wide-web, please send a note to
  14.  * pajoye@php.net so we can mail you a copy immediately.
  15.  *
  16.  * @category  Validate
  17.  * @package   Validate_NL
  18.  * @author    Dave Mertens <zyprexia@php.net>
  19.  * @author    Pierre-Alain Joye <pajoye@php.net>
  20.  * @copyright 1997-2005 Dave Mertens
  21.  * @license   http://www.opensource.org/licenses/bsd-license.php  new BSD
  22.  * @version   CVS: $Id: NL.php,v 1.18 2007/08/07 22:31:42 kguest Exp $
  23.  * @link      http://pear.php.net/package/Validate_NL
  24.  */
  25.  
  26. //Any dutch phonenumber
  27. define('VALIDATE_NL_PHONENUMBER_TYPE_ANY'0);
  28. //only normal phonenumber (mobile numers are not allowed)
  29. define('VALIDATE_NL_PHONENUMBER_TYPE_NORMAL'1);
  30. //only mobile numbers are allowed
  31. define('VALIDATE_NL_PHONENUMBER_TYPE_MOBILE'2);
  32.  
  33. /**
  34.  * Data validation class for the Netherlands
  35.  *
  36.  * This class provides methods to validate:
  37.  *  - Social insurance number (aka SIN)
  38.  *  - Bank account number
  39.  *  - Telephone number
  40.  *  - Postal code
  41.  *
  42.  * @category  Validate
  43.  * @package   Validate_NL
  44.  * @author    Dave Mertens <zyprexia@php.net>
  45.  * @copyright 1997-2005 Dave Mertens
  46.  * @license   http://www.opensource.org/licenses/bsd-license.php  new BSD
  47.  * @version   Release: @package_version@
  48.  * @link      http://pear.php.net/package/Validate_NL
  49.  */
  50. {
  51.     /**
  52.      * Validate a NL postcode
  53.      *
  54.      * @param string $postcode NL postcode to validate
  55.      * @param bool   $strong   optional; strong checks (e.g. against a list
  56.      *                          of postcodes) (not implanted)
  57.      *
  58.      * @return  bool    true if postcode is ok, false otherwise
  59.      */
  60.     function postalCode($postcode$strong = false)
  61.     {
  62.         // $strong is not used here at the moment; added for API compatibility
  63.         // checks might be added at a later stage
  64.  
  65.         // '1234 AB', '1234AB', '1234 ab'
  66.         return (bool)ereg('^[0-9]{4}\ {0,1}[A-Za-z]{2}$'$postcode)
  67.     }
  68.  
  69.     /**
  70.      * Validate a phonenumber
  71.      *
  72.      * @param string $number Dutch phonenumber (can be in international format
  73.      *                        (eg +31 or 0031)
  74.      * @param int    $type   Type of phonenumber to check
  75.      *
  76.      * @return  bool    true if (phone) number is correct
  77.      */
  78.     function phoneNumber($number$type = PHONENUMBER_TYPE_ANY)
  79.     {
  80.         $result = false;
  81.  
  82.         //we need at least 9 digits
  83.         if (ereg("^[+0-9]{9,}$"$number)) {
  84.             $number substr($numberstrlen($number- 9);
  85.  
  86.             //we only use the last 9 digits (so no troubles with 
  87.             //international numbers)
  88.             if (strlen($number>= 9{
  89.                 switch ($type{
  90.                 case VALIDATE_NL_PHONENUMBER_TYPE_ANY:
  91.                     //we have a 9 digit numeric number.
  92.                     $result = true;     
  93.                     break;
  94.                 case VALIDATE_NL_PHONENUMBER_TYPE_NORMAL:
  95.                     //normal phonenumbers don't begin with 6 (00316, +316 
  96.                     //and 06 are reserved for mobile numbers)
  97.                     if ((int)$number[0!= 6)
  98.                         $result = true;     
  99.                     break;
  100.                 case VALIDATE_NL_PHONENUMBER_TYPE_MOBILE:
  101.                     //mobilenumbers start with a 6
  102.                     if ((int)$number[0== 6)
  103.                         $result = true;     
  104.                     break;
  105.                 }
  106.             }
  107.         }
  108.  
  109.         return $result;
  110.     }
  111.  
  112.  
  113.     /**
  114.      * Social Security Number check (very simple, just a 9 digit number..)
  115.      * In Dutch SoFi (Sociaal Fiscaal) nummer
  116.      *
  117.      * @param string $ssn Dutch social security number
  118.      *
  119.      * @return bool true if SSN number is correct
  120.      */
  121.     function ssn($ssn)
  122.     {
  123.         return (bool) ereg("^[0-9]{9}$"$ssn);
  124.     }
  125.  
  126.     /**
  127.      * Bankaccount validation check (based on 11proef)
  128.      *
  129.      * @param string $number Dutch bankaccount number
  130.      *
  131.      * @return bool true is bankaccount number 'seems' correct
  132.      */
  133.     function bankAccountNumber($number)
  134.     {
  135.         $result   = false;        //by default we return false
  136.         $checksum = 0;
  137.  
  138.         if (is_numeric((string)$number&& strlen((string)$number<= 10{
  139.             //make sure we have a 10 digit number
  140.             $number str_pad($number10'0'STR_PAD_LEFT);  
  141.  
  142.             //create checksum
  143.             for ($i = 0; $i < 10; $i++{
  144.                 $checksum += ((int)$number[$i(10 - $i));
  145.             }
  146.  
  147.             //Banknumber is 'correct' if we can divide checksum by 11
  148.             if ($checksum > 0 && $checksum % 11 == 0)
  149.                 $result = true;
  150.         }
  151.  
  152.         //return result
  153.         return $result;
  154.     }
  155.  
  156. }
  157. ?>

Documentation generated on Mon, 23 Mar 2009 01:00:02 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.