Permalink
Browse files

Seperated to own package

  • Loading branch information...
1 parent 574c5e7 commit b837d22a3353c071163b975ec1f5c20b57b8cbf6 @CloCkWeRX CloCkWeRX committed Dec 17, 2011
Showing with 0 additions and 358 deletions.
  1. +0 −156 Validate/DK.php
  2. +0 −87 package_DK.xml
  3. +0 −115 tests/validate_DK.phpt
View
@@ -1,156 +0,0 @@
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Specific validation methods for data used in DK
- *
- * 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_DK
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>
- * @copyright 2003-2005 Jesper Veggerby Hansen
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate_DK
- */
-
-/**
- * Data validation class for Denmark
- *
- * This class provides methods to validate:
- *
- * - Postal code
- * - Social Security Number (CPR Nummer)
- * - Danish telephone number
- * - Car registration number
- *
- * @category Validate
- * @package Validate_DK
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>
- * @copyright 2003-2005 Jesper Veggerby Hansen
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php. net/package/Validate_DK
- */
-class Validate_DK
-{
-
- /**
- * validates a postcode
- *
- * Four digit postal code, maybe with a leading 'DK-'
- *
- * @param string $postcode the postcode to be validated
- * @param bool $strong optional; strong checks (e.g. against a list
- * of postcodes)
- *
- * @access public
- * @return bool
- */
- function postalCode($postcode, $strong=false)
- {
- $preg = "/^(DK-)?[0-9]{4}$/";
- $match = preg_match($preg, $postcode)? true : false;
- return $match;
- }
-
- /**
- * validates a CPR Number (ssn equiv)
- *
- * The danish CPR number is a 8 digit number with the birthdate as
- * ddmmyy-xxxy where xxxy is a four digit control number.
- *
- * The 10 digits are summarized with coefficients 4, 3, 2, 7, 6, 5, 4, 3, 2
- * and 1. If the sum is divisible by 11 the control is correct.
- *
- * The last digit of the control number (y) is also dependend on gender, if
- * y is odd it's a male cpr number and if even a female.
- *
- * @param string $cpr CPR number
- * @param string $gender The gender to validate for 'M' for male, 'F'
- * for female, false or omitted to not perform
- * the check.
- *
- * @access public
- * @return bool
- */
- function ssn($cpr, $gender = false)
- {
- // remove spaces and uppercase it
- $preg = "/^[0-3][0-9][0-1]\d{3}-\d{4}?/";
- if (preg_match($preg, $cpr)) {
-
- $cpr = str_replace('-', '', $cpr);
-
- $y = substr($cpr, -1);
- switch ($gender) {
- case 'M':
- $genderOK = (($y % 2) == 1);
- break;
- case 'F':
- $genderOK = (($y % 2) == 0);
- break;
- default:
- $genderOK = true;
- break;
- }
-
- return $genderOK;
- } else {
- return false;
- }
- }
-
- /**
- * Validate danish telephone number
- *
- * Simple check: 8 digits when removing (, ), -, +, ., ' '
- *
- * @param string $tel the tel number
- *
- * @access public
- * @return bool
- */
- function phoneNumber($tel)
- {
- // just checks to see if it is numeric and starts with a 0
- // remove any wierd characters like (,),-,. etc
- $tel = str_replace(Array('(', ')', '-', '+', '.', ' '), '', $tel);
- $preg = "/^[0-9]{8}$/";
- $match = (preg_match($preg, $tel)) ? true : false;
- return $match;
- }
-
- /**
- * Validates a car registration number
- *
- * Format: AA XX YYY
- *
- * Where AA are 2 letter UPPERCASE A-Z
- *
- * @param string $reg the registration number
- *
- * @access public
- * @return bool
- */
- function carReg($reg)
- {
- $prepreg = "/^[A-Z]{2} [0-9]{2} [0-9]{3}$/";
- if (preg_match($prepreg, $reg)) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-?>
View
@@ -1,87 +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_DK</name>
- <channel>pear.php.net</channel>
- <summary>Validation class for Denmark</summary>
- <description>Package containes locale validation for Denmark such as:
- * Postal Code
- * Social Security Number (CPR Nummer)
- * Phone number
- * Car Registration number</description>
- <lead>
- <name>Jesper Veggerby</name>
- <user>nosey</user>
- <email>pear.nosey@veggerby.dk</email>
- <active>yes</active>
- </lead>
- <date>2009-03-24</date>
- <time>06:57:50</time>
- <version>
- <release>0.1.2</release>
- <api>0.1.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 #8375 phpdoc wrong
-Bug #11825 phpcs/Coding Standards issues highlighted in DK.php</notes>
- <contents>
- <dir baseinstalldir="/" name="/">
- <file baseinstalldir="/" md5sum="680752ab3626fe04e66d117aea9c639f" name="tests/validate_DK.phpt" role="test" />
- <file baseinstalldir="/" md5sum="69f7a2c6b0bb39d4e881b96477b8ab2a" name="Validate/DK.php" role="php" />
- <file baseinstalldir="/" md5sum="581e291fd739c0eaf15ccdecfded584d" name="package_DK.xml" role="data" />
- <file baseinstalldir="/" md5sum="7073f9a84fa6da71e7a505a777dda302" name="LICENSE" role="doc" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.4.6</min>
- </php>
- <pearinstaller>
- <min>1.6.0</min>
- </pearinstaller>
- <package>
- <name>Validate</name>
- <channel>pear.php.net</channel>
- <min>0.5.0</min>
- </package>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2005-10-05</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>Initial release</notes>
- </release>
- <release>
- <version>
- <release>0.1.2</release>
- <api>0.1.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2009-03-24</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>QA release
-Updated to package 2.0
-Bug #8375 phpdoc wrong
-Bug #11825 phpcs/Coding Standards issues highlighted in DK.php</notes>
- </release>
- </changelog>
-</package>
View
@@ -1,115 +0,0 @@
---TEST--
-validate_DK.phpt: Unit tests for 'Validate/DK.php'
---FILE--
-<?php
-// $Id$
-// Validate test script
-$noYes = array('NO', 'YES');
-require 'Validate/DK.php';
-
-echo "Test Validate_DK\n";
-echo "****************\n";
-
-$postalCodes = array(
- '8250', // OK
- 'DK-8250', // OK
- '250', // NOK
- '250a', // NOK
- 'DK-250', // NOK
- 'Da-8250', // NOK
- 'DK-250a'); // NOK
-
-$phonenumbers = array(
- '21021212', // OK
- '2121212'); // NOK
-
-$ssns = array(
- array(
- '010192-1212',
- false // no gender (is female)
- ), // OK
- array(
- '211277-8317',
- false // no gender (is male)
- ), // OK
- array(
- '211277-8317',
- 'M' // is male?
- ), // OK
- array(
- '010192-1212',
- 'F' // is female?
- ), // OK
- array(
- '010192-1212',
- 'M' // is male?
- ), // NOK !(is male)
- array(
- '01a19.-1212',
- false // no gender (wrong format)
- ), // NOK !(wrong format)
- array(
- 'no-way',
- false // no gender (wrong format)
- ), // NOK !(wrong format)
- array(
- '010192-1211',
- false // no gender
- ), // OK (cipher does not match)
- array(
- '012092-1211',
- false // no gender
- ) // NOK (Wrong format)
- );
-
-$carregs = array(
- 'XC 21 261', // OK
- 'DO 216'); // NOK
-
-echo "Test postalCode\n";
-foreach ($postalCodes as $postalCode) {
- echo "{$postalCode}: ".$noYes[Validate_DK::postalCode($postalCode)]."\n";
-}
-
-echo "Test ssn\n";
-foreach ($ssns as $ssn) {
- echo "{$ssn[0]}, {$ssn[1]}: ".$noYes[Validate_DK::ssn($ssn[0], $ssn[1])]."\n";
-}
-
-echo "Test phonenumber\n";
-foreach ($phonenumbers as $phonenumber) {
- echo "{$phonenumber}: ".$noYes[Validate_DK::phoneNumber($phonenumber)]."\n";
-}
-
-echo "Test carreg\n";
-foreach ($carregs as $carreg) {
- echo "{$carreg}: ".$noYes[Validate_DK::carReg($carreg)]."\n";
-}
-?>
---EXPECT--
-Test Validate_DK
-****************
-Test postalCode
-8250: YES
-DK-8250: YES
-250: NO
-250a: NO
-DK-250: NO
-Da-8250: NO
-DK-250a: NO
-Test ssn
-010192-1212, : YES
-211277-8317, : YES
-211277-8317, M: YES
-010192-1212, F: YES
-010192-1212, M: NO
-01a19.-1212, : NO
-no-way, : NO
-010192-1211, : YES
-010120-1211, : NO
-Test phonenumber
-21021212: YES
-2121212: NO
-Test carreg
-XC 21 261: YES
-DO 216: NO

0 comments on commit b837d22

Please sign in to comment.