Permalink
Browse files

Split Validate/Validate_NL

  • Loading branch information...
1 parent d008b87 commit dfc8ee5e0c7d93c6559429e57110e2ec55ca7807 @CloCkWeRX CloCkWeRX committed Nov 26, 2011
Showing with 0 additions and 343 deletions.
  1. +0 −158 Validate/NL.php
  2. +0 −85 package_NL.xml
  3. +0 −100 tests/validate_NL.phpt
View
@@ -1,158 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Specific validation methods for data used in the Netherlands
- *
- * PHP Versions 4 and 5
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_NL
- * @author Dave Mertens <zyprexia@php.net>
- * @author Pierre-Alain Joye <pajoye@php.net>
- * @copyright 1997-2005 Dave Mertens
- * @license http://www.opensource.org/licenses/bsd-license.php new BSD
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate_NL
- */
-
-//Any dutch phonenumber
-define('VALIDATE_NL_PHONENUMBER_TYPE_ANY', 0);
-//only normal phonenumber (mobile numers are not allowed)
-define('VALIDATE_NL_PHONENUMBER_TYPE_NORMAL', 1);
-//only mobile numbers are allowed
-define('VALIDATE_NL_PHONENUMBER_TYPE_MOBILE', 2);
-
-/**
- * Data validation class for the Netherlands
- *
- * This class provides methods to validate:
- * - Social insurance number (aka SIN)
- * - Bank account number
- * - Telephone number
- * - Postal code
- *
- * @category Validate
- * @package Validate_NL
- * @author Dave Mertens <zyprexia@php.net>
- * @copyright 1997-2005 Dave Mertens
- * @license http://www.opensource.org/licenses/bsd-license.php new BSD
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Validate_NL
- */
-class Validate_NL
-{
- /**
- * Validate a NL postcode
- *
- * @param string $postcode NL postcode to validate
- * @param bool $strong optional; strong checks (e.g. against a list
- * of postcodes) (not implanted)
- *
- * @return bool true if postcode is ok, false otherwise
- */
- function postalCode($postcode, $strong = false)
- {
- // $strong is not used here at the moment; added for API compatibility
- // checks might be added at a later stage
-
- // '1234 AB', '1234AB', '1234 ab'
- return (bool) preg_match('/^[0-9]{4}\ {0,1}[A-Za-z]{2}$/', $postcode);
- }
-
- /**
- * Validate a phonenumber
- *
- * @param string $number Dutch phonenumber (can be in international format
- * (eg +31 or 0031)
- * @param int $type Type of phonenumber to check
- *
- * @return bool true if (phone) number is correct
- */
- function phoneNumber($number, $type = PHONENUMBER_TYPE_ANY)
- {
- $result = false;
-
- //we need at least 9 digits
- if (preg_match("/^[+0-9]{9,}$/", $number)) {
- $number = substr($number, strlen($number) - 9);
-
- //we only use the last 9 digits (so no troubles with
- //international numbers)
- if (strlen($number) >= 9) {
- switch ($type) {
- case VALIDATE_NL_PHONENUMBER_TYPE_ANY:
- //we have a 9 digit numeric number.
- $result = true;
- break;
- case VALIDATE_NL_PHONENUMBER_TYPE_NORMAL:
- //normal phonenumbers don't begin with 6 (00316, +316
- //and 06 are reserved for mobile numbers)
- if ((int)$number[0] != 6)
- $result = true;
- break;
- case VALIDATE_NL_PHONENUMBER_TYPE_MOBILE:
- //mobilenumbers start with a 6
- if ((int)$number[0] == 6)
- $result = true;
- break;
- }
- }
- }
-
- return $result;
- }
-
-
- /**
- * Social Security Number check (very simple, just a 9 digit number..)
- * In Dutch SoFi (Sociaal Fiscaal) nummer
- *
- * @param string $ssn Dutch social security number
- *
- * @return bool true if SSN number is correct
- */
- function ssn($ssn)
- {
- return (bool) preg_match("/^[0-9]{9}$/", $ssn);
- }
-
- /**
- * Bankaccount validation check (based on 11proef)
- *
- * @param string $number Dutch bankaccount number
- *
- * @return bool true is bankaccount number 'seems' correct
- */
- function bankAccountNumber($number)
- {
- $result = false; //by default we return false
- $checksum = 0;
-
- if (is_numeric((string)$number) && strlen((string)$number) <= 10) {
- //make sure we have a 10 digit number
- $number = str_pad($number, 10, '0', STR_PAD_LEFT);
-
- //create checksum
- for ($i = 0; $i < 10; $i++) {
- $checksum += ((int)$number[$i] * (10 - $i));
- }
-
- //Banknumber is 'correct' if we can divide checksum by 11
- if ($checksum > 0 && $checksum % 11 == 0)
- $result = true;
- }
-
- //return result
- return $result;
- }
-
-}
-?>
View
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.7.2" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
- <name>Validate_NL</name>
- <channel>pear.php.net</channel>
- <summary>Validation class for NL</summary>
- <description>Package containes locale validation for NL such as:
- * SSN
- * Postal Code
- * Phone Number
- * Bank Account Number (based on 11proef)</description>
- <lead>
- <name>Dave Mertens</name>
- <user>zyprexia</user>
- <email>zyprexia@php.net</email>
- <active>yes</active>
- </lead>
- <date>2009-03-23</date>
- <time>00:31:39</time>
- <version>
- <release>0.5.2</release>
- <api>0.5.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>QA release
-Updated to package 2.0
-Bug #8391 - Case with no return
-Bug #11783 - PHPCS</notes>
- <contents>
- <dir baseinstalldir="/" name="/">
- <file baseinstalldir="/" md5sum="b9f8fd9c12960ebcf45a47fa8c0fa535" name="tests/validate_NL.phpt" role="test" />
- <file baseinstalldir="/" md5sum="9ad1134272acb0753d64896ce6a87a8a" name="Validate/NL.php" role="php" />
- <file baseinstalldir="/" md5sum="7073f9a84fa6da71e7a505a777dda302" name="LICENSE" role="doc" />
- <file baseinstalldir="/" md5sum="9517519ff010f48914aec14953d4e658" name="package_NL.xml" role="data" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.4.9</min>
- </php>
- <pearinstaller>
- <min>1.6.0</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.5.0</release>
- <api>0.5.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2005-05-20</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>- Split from Validate into independent package
-- CS fixes
-- BC break!
-postalCode unified between countries (name wise), now all postcode validation funcs are named postalCode</notes>
- </release>
- <release>
- <version>
- <release>0.5.2</release>
- <api>0.5.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2009-03-23</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>QA release
-Updated to package 2.0
-Bug #8391 - Case with no return
-Bug #11783 - PHPCS</notes>
- </release>
- </changelog>
-</package>
View
@@ -1,100 +0,0 @@
---TEST--
-validate_NL.phpt: Unit tests for require_once( "Validate/NL.php" )
---FILE--
-<?php
-// $Id$
-// Validate test script
-$noYes = array('NO', 'YES');
-require_once( "Validate/NL.php" );
-
-echo "Test Validate_NL\n";
-echo "****************\n";
-
-$postalCodes = array(
- "1234 AB", // OK
- "1234 ab", // OK
- "1234AB", // OK
- "1234ab", // OK
- "1234aB", // OK
- "123456", // NOK
- "1234", // NOK
- "AB1234", // NOK
- "aB12 34" // NOK
-);
-
-$phoneNumbers = array(
- array("0612345678" , VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), // OK
- array("0031612345678" , VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), // OK
- array("+31612345678" , VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), // OK
- array("0101234567" , VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), // OK
- array("+31101234567" , VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), // OK
- array("0031101234567" , VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), // OK
- array("0612345678" , VALIDATE_NL_PHONENUMBER_TYPE_ANY), // OK
- array("+31101234567" , VALIDATE_NL_PHONENUMBER_TYPE_ANY), // OK
- array("+31101234567" , VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), // NOK
- array("+0031612345678", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL) // NOK
-);
-
-$SSNs = array(
- "12345678", // NOK
- "1234567890", // NOK
- "123456789" // OK
-);
-
-$bankAccountNumbers = array(
- "640000231", // OK
- "640400231" // NOK
-);
-
-echo "Test postalCode\n";
-foreach ($postalCodes as $postalCode) {
- echo "{$postalCode}: ".$noYes[Validate_NL::postalCode($postalCode)]."\n";
-}
-
-echo "Test phoneNumber\n";
-foreach ($phoneNumbers as $phoneNumber) {
- echo "{$phoneNumber[0]} ".($phoneNumber[1]? "(10)" : "(7)").": ".
- $noYes[Validate_NL::phoneNumber($phoneNumber[0], $phoneNumber[1])]."\n";
-}
-
-echo "Test SSN\n";
-foreach ($SSNs as $SSN) {
- echo "{$SSN}: ".$noYes[Validate_NL::SSN($SSN)]."\n";
-}
-
-echo "Test bankAccountNumber\n";
-foreach ($bankAccountNumbers as $bankAccountNumber) {
- echo "{$bankAccountNumber}: ".$noYes[Validate_NL::bankAccountNumber($bankAccountNumber)]."\n";
-}
-?>
---EXPECT--
-Test Validate_NL
-****************
-Test postalCode
-1234 AB: YES
-1234 ab: YES
-1234AB: YES
-1234ab: YES
-1234aB: YES
-123456: NO
-1234: NO
-AB1234: NO
-aB12 34: NO
-Test phoneNumber
-0612345678 (10): YES
-0031612345678 (10): YES
-+31612345678 (10): YES
-0101234567 (10): YES
-+31101234567 (10): YES
-0031101234567 (10): YES
-0612345678 (7): YES
-+31101234567 (7): YES
-+31101234567 (10): NO
-+0031612345678 (10): NO
-Test SSN
-12345678: NO
-1234567890: NO
-123456789: YES
-Test bankAccountNumber
-640000231: YES
-640400231: NO

0 comments on commit dfc8ee5

Please sign in to comment.