cvs: pear /Validate package_FI.xml /Validate/Validate FI.php /Validate/tests validate_FI_bankAccount.phpt validate_FI_bikeLicensePlate.phpt
validate_FI_businessId.phpt validate_FI_carLicensePlate.phpt validate_FI_creditCard.phpt validate_FI_finuid.phpt validate_FI_partyId.phpt
validate_FI_phoneNumber.phpt validate_FI_pin.phpt validate_FI_postalCode.phpt validate_FI_refNum.phpt validate_FI_vatNumber.phpt
| From: | Jani Mikkonen | Date: | Fri, 23 Mar 2007 08:54:10 +0000 |
| Subject: | cvs: pear /Validate package_FI.xml /Validate/Validate FI.php /Validate/tests validate_FI_bankAccount.phpt validate_FI_bikeLicensePlate.phpt validate_FI_businessId.phpt validate_FI_carLicensePlate.phpt validate_FI_creditCard.phpt validate_FI_finuid.phpt validate_FI_partyId.phpt validate_FI_phoneNumber.phpt validate_FI_pin.phpt validate_FI_postalCode.phpt validate_FI_refNum.phpt validate_FI_vatNumber.phpt |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-45368@lists.php.net to get a copy of this message | ||
janisto Fri Mar 23 08:54:10 2007 UTC
Added files:
/pear/Validate/Validate FI.php
/pear/Validate package_FI.xml
/pear/Validate/tests validate_FI_bankAccount.phpt
validate_FI_bikeLicensePlate.phpt
validate_FI_businessId.phpt
validate_FI_carLicensePlate.phpt
validate_FI_creditCard.phpt
validate_FI_finuid.phpt
validate_FI_partyId.phpt
validate_FI_phoneNumber.phpt
validate_FI_pin.phpt
validate_FI_postalCode.phpt
validate_FI_refNum.phpt
validate_FI_vatNumber.phpt
Log:
Initial release
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/FI.php?view=markup&rev=1.1 Index: pear/Validate/Validate/FI.php +++ pear/Validate/Validate/FI.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ // +----------------------------------------------------------------------+ // | Copyright (c) 2006 Jani Mikkonen | // +----------------------------------------------------------------------+ // | 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 BSD license 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. | // +----------------------------------------------------------------------+ // | Author: Jani Mikkonen <jani@mikkonen.info> | // +----------------------------------------------------------------------+ // /** * Specific validation methods for data used in Finland * * @category Validate * @package Validate_FI * @author Jani Mikkonen <jani@mikkonen.info> * @copyright 2006 Jani Mikkonen * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: FI.php,v 1.1 2007/03/23 08:54:10 janisto Exp $ * @link http://pear.php.net/package/Validate_FI */ // {{{ class Validate_FI /** * Validation class for Finland * * This class provides methods to validate: * - Postal Code * - Telephone Number * - Car License Plate Number * - Motorbike License Plate Number * - Personal Identity Number (HETU) * - Unique Identification Number (SATU) * - Business ID Number (Y-tunnus) * - Party Identification Number (OVT-tunnus) * - Value Added Tax Number (ALV-numero) * - Bank Account Number (tilinumero) * - Bank Reference Number (viitenumero) * - Credit Card Number * * @category Validate * @package Validate_FI * @author Jani Mikkonen <jani@mikkonen.info> * @copyright 2006 Jani Mikkonen * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version Release: @package_version@ * @link http://pear.php.net/package/Validate_FI */ class Validate_FI { // {{{ bool Validate_FI::postalCode( string $number [, bool $strong = false] ) /** * Validate Finnish postal code. * * Five digit postal code, maybe with a leading 'FI-'. * * Format: XXXXX or FI-XXXXX * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $postalCode = '00100'; * if ( Validate_FI::postalCode($postalCode) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the postal code to be validated * @param bool optional; strong checks * (e.g. against a list of postal codes) * @return bool true if postal code is valid, false otherwise */ function postalCode($number, $strong=false) { return (preg_match("/^(FI-)?[0-9]{5}$/", $number)) ? true : false; } // }}} // {{{ bool Validate_FI::phoneNumber( string $number ) /** * Validate Finnish telephone number. * * Simple check: number must be numeric when (, ), -, +, ., ' ' * chars are removed and 3-20 digit number. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $phoneNumber = '+358 40 1234567'; * if ( Validate_FI::phoneNumber($phoneNumber) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the telephone number to be validated * @return bool true if telephone number is valid, false otherwise */ function phoneNumber($number){ $number = str_replace(Array('(', ')', '-', '+', '.', ' '), '', $number); return (preg_match("/^[0-9]{3,20}$/", $number)) ? true : false; } // }}} // {{{ bool Validate_FI::carLicensePlate( string $number ) /** * Validate Finnish car license plate number. * * Format: AAA-XXX, CD-XXXX or C-XXXXX * * AAA-XXX: AAA is 2-3 letters UPPERCASE A-Z and XXX is 1-3 numbers * CD-XXXX: CD- and XXXX is 1-4 numbers (diplomat licence plate) * C-XXXXX: C- and XXXXX is 1-5 numbers (other tax-free diplomat licence plate) * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $carLicensePlate = 'ABC-123'; * if ( Validate_FI::carLicensePlate($carLicensePlate) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the license plate number to be validated * @return bool true if license plate number is valid, false otherwise * @link http://www.ake.fi/AKE/Rekisterointi/Suomen_rekisterikilvet/ */ function carLicensePlate($number){ // diplomat licence plate if (preg_match("/^CD-[0-9]{1,4}$/", $number)) { return true; } // other tax-free diplomat licence plate if (preg_match("/^C-[0-9]{1,5}$/", $number)) { return true; } // regular licence plate if (preg_match("/^[A-Z]{2,3}-[0-9]{1,3}$/", $number)) { return true; } return false; } // }}} // {{{ bool Validate_FI::bikeLicensePlate( string $number ) /** * Validate Finnish motorbike license plate number. * * Format: AAAXXX * * Where AAA is 2-3 letters UPPERCASE A-Z and XXX is 1-3 numbers. * Letters and numbers are actually in separate lines. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $bikeLicensePlate = 'ABC123'; * if ( Validate_FI::bikeLicensePlate($bikeLicensePlate) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the license plate number to be validated * @return bool true if license plate number is valid, false otherwise * @link http://www.ake.fi/AKE/Rekisterointi/Suomen_rekisterikilvet/ */ function bikeLicensePlate($number){ return (preg_match("/^[A-Z]{2,3}(\n)?[0-9]{1,3}$/", $number)) ? true : false; } // }}} // {{{ mixed Validate_FI::pin( string $number [, bool $info = false] ) /** * Validate Personal Identity Number (HETU). * * The Finnish PIN number (HETU) aka Social Security Number (SSN) * is a 11 digit number with birthdate as ddmmyycxxxy where c is century, * xxx is a three digit individual number and the last digit is a * control number (y). * * If xxx is odd it's a male PIN number and if even a female. * * Return gender (Male or Female) and date of birth (YYYY-MM-DD) in array if * PIN is valid, is available by switching $info (2nd parameter) to true. * * Example: 010101-123N would be a male and born in 1st of January 1901. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $pin = '010101-123N'; * if ( Validate_FI::pin($pin) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * if ( $userinfo = Validate_FI::pin($pin, true) ) { * print_r($userinfo); * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number PIN number to be validated * @param bool optional; Return gender and date of birth on success * @return mixed Returns true or false if $info = false or * gender (Male or Female) and date of birth (YYYY-MM-DD) * in array if PIN is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#hetu1 */ function pin($number, $info = false) { $pin = strtoupper($number); static $control = array("0","1","2","3","4","5","6","7","8","9", "A","B","C","D","E","F","H","J","K","L", "M","N","P","R","S","T","U","V","W","X","Y"); static $century = array('+' => "18", '-' => "19", 'A' => "20"); if(ereg("^([0-9]{2})([0-9]{2})([0-9]{2})([+-A]{1})([0-9]{3})([0-9A-Z]{1})$",$pin,$regs)) { // Validate date of birth. Must be a Gregorian date. if(checkdate($regs[2],$regs[1],$century[$regs[4]].$regs[3])) { if($control[intval($regs[1].$regs[2].$regs[3].$regs[5])%31] == $regs[6]) { if($info) { $gen = ($regs[5]%2==1) ? 'Male' : 'Female'; $dob = $century[$regs[4]].$regs[3].'-'.$regs[2].'-'.$regs[1]; return array($gen, $dob); } else { return true; } } } } return false; } // }}} // {{{ bool Validate_FI::finuid( string $number ) /** * Validate Finnish Unique Identification Number (SATU). * * FINUID (SATU) is a 9 digit number. The last digit is a control number. * * Example: 10011187H * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $finuid = '10011187H'; * if ( Validate_FI::finuid($finuid) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number FINUID number to be validated * @return bool true if FINUID is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#satu */ function finuid($number) { $number = strtoupper($number); static $control = array("0","1","2","3","4","5","6","7","8","9", "A","B","C","D","E","F","H","J","K","L", "M","N","P","R","S","T","U","V","W","X","Y"); if(ereg("^([0-9]{8})([0-9A-Z]{1})$",$number,$regs)) { if($control[intval($regs[1])%31] == $regs[2]) { return true; } } return false; } // }}} // {{{ bool Validate_FI::businessId( string $number ) /** * Validate Finnish Business ID (Y-tunnus). * * The Finnish Business ID number (Y-tunnus) is a 9 digit number. * The last digit is a control number (y). * * Format: xxxxxxx-y * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $businessId = '1572860-0'; * if ( Validate_FI::businessId($businessId) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number Business ID number to be validated * @return bool true if Business ID is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#y-tunnus2 */ function businessId($number) { if (preg_match("/^[0-9]{6,7}-[0-9]{1}$/", $number)) { list($num, $control) = split('[-]', $number); // Add leading zeros if number is < 7 $num = str_pad($num, 7, 0, STR_PAD_LEFT); $controlSum = 0; $controlSum += (int)substr($num, 0, 1)*7; $controlSum += (int)substr($num, 1, 1)*9; $controlSum += (int)substr($num, 2, 1)*10; $controlSum += (int)substr($num, 3, 1)*5; $controlSum += (int)substr($num, 4, 1)*8; $controlSum += (int)substr($num, 5, 1)*4; $controlSum += (int)substr($num, 6, 1)*2; $controlSum = $controlSum%11; if($controlSum == 0) { return ($controlSum == $control) ? true : false; } else if($controlSum >= 2 && $controlSum <= 10 ) { return ((11 - $controlSum) == $control) ? true : false; } } return false; } // }}} // {{{ bool Validate_FI::partyId( int $number ) /** * Validate Finnish Party Identification number (OVT-tunnus). * * The Finnish Party Identification number (OVT-tunnus) is a 12-17 * digit number and it is generated from Business ID. * * Example: 0037AAAAAAAABBBBB, 0037 indicates Finland, AAAAAAAA is the * Business ID and BBBBB is optional organization number. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $partyId = '003715728600'; * if ( Validate_FI::partyId($partyId) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param int $number Party Identification number to be validated * @return bool true if number is valid, false otherwise * @see Validate_FI::businessId() * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#alv-numero */ function partyId($number) { if (preg_match("/^[0-9]{12,17}$/", $number)) { $countryCode = substr($number, 0, 4); $controlNum = substr($number, 11, 1); $businessNum = substr($number, 4, 7); $businessId = $businessNum.'-'.$controlNum; if($countryCode == '0037' && Validate_FI::businessId($businessId)) { return true; } } return false; } // }}} // {{{ bool Validate_FI::vatNumber( string $number ) /** * Validate Finnish Value Added Tax number (ALV-numero). * * The Finnish VAT number (ALV-numero) is maximum * of 14 digits and is generated from Business ID. * * Format: FIXXXXXXXX * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $vatNumber = 'FI15728600'; * if ( Validate_FI::vatNumber($vatNumber) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number VAT number to be validated * @return bool true if VAT number is valid, false otherwise * @see Validate_FI::businessId() * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#alv-numero */ function vatNumber($number) { $countryCode = substr($number, 0, 2); $controlNum = substr($number, -1, 1); $businessNum = substr($number, 2, -1); $businessId = $businessNum.'-'.$controlNum; if($countryCode == 'FI' && Validate_FI::businessId($businessId)) { return true; } return false; } // }}} // {{{ bool Validate_FI::bankAccount( string $number ) /** * Validate Finnish bank account number. * * This method checks the bank account number according to * Finnish Bank Association. * * Format: XXXXXX-XXXXXXXX, 6 digits, - and 2-8 digits. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $bankAccount = '159030-776'; * if ( Validate_FI::bankAccount($bankAccount) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number Finnish bank account number to be validated * @return bool true if bank account is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#pankkitili * @link http://www.pankkiyhdistys.fi/sisalto/upload/pdf/tilinrorakenne.pdf */ function bankAccount($number) { if (preg_match("/^[0-9]{6}-[0-9]{2,8}$/", $number)) { // Bank groups are identified by the first digit $bankType = substr($number, 0, 1); // Group 1: First digit is 1, 2, 3, 6 or 8 $bankGroup1 = array('1','2','3','6','8'); // Group 2: First digit is 4 or 5 $bankGroup2 = array('4','5'); // split account number ereg("([0-9]{6})-([0-9]{2,8})", $number, $regs); if (in_array($bankType, $bankGroup1)) { // Group 1: 999999-99999 -> 999999-00099999 $number = $regs[1] . str_pad($regs[2], 8, 0, STR_PAD_LEFT); // Group 2: 999999-99999 -> 999999-90009999 } else if (in_array($bankType, $bankGroup2)) { $number = $regs[1] . substr($regs[2], 0, 1) . str_pad(substr($regs[2], 1, 7), 7, 0, STR_PAD_LEFT); } // Now when we have a 14 digit bank account number, we can validate it. return Validate_FI::_mod10($number); } return false; } // }}} // {{{ bool Validate_FI::refNum( string $number ) /** * Validate Finnish bank reference number. * * This method checks the bank reference number according to * Finnish Bank Association. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $refNum = '61 74354'; * if ( Validate_FI::refNum($refNum) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number Finnish bank reference number to be validated (spaces and dashes tolerated) * @return bool true if reference number is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#viitenumero */ function refNum($number) { // Remove non-numeric characters from $refnum. Only 4-20 digit number. $refnum = ereg_replace('[^0-9]+', '', $number); // The last digit is a control number. $controlNum = substr($refnum, -1, 1); // Subtract control number from the $refnum. $refNumCheck = substr($refnum, 0, strlen($refnum)-1); if(preg_match("/^[0-9]{3,19}$/", $refNumCheck)) { // remove leading zeros $refNumCheck = ltrim($refNumCheck, 0); $mul = 7; $refSum = 0; for($refLength = strlen($refNumCheck); $refLength > 0; $refLength--) { $refSum += substr($refNumCheck, $refLength - 1, 1) * $mul; switch ($mul) { case 7: $mul = 3; break; case 3: $mul = 1; break; case 1: $mul = 7; break; } } $refSum = substr(10 - ($refSum % 10), -1); if($refSum == $controlNum){ return true; } } return false; } // }}} // {{{ bool Validate_FI::creditCard( string $number ) /** * Validate credit card number. * * This method checks the credit card number according to Luhn algorithm. * This method doesn't guarantee that the card is legitimate. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $creditCard = '5427 0073 1297 6425'; * if ( Validate_FI::creditCard($creditCard) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number credit card number to be validated * (spaces and dashes tolerated) * @return bool true if credit card number is valid, false otherwise */ function creditCard($number) { // Remove non-numeric characters from $number $number = ereg_replace('[^0-9]+', '', $number); // Validate number return Validate_FI::_mod10($number); } // }}} // {{{ bool Validate_FI::_mod10( string $number ) /** * Validate number according to Luhn algorithm (mod 10). * * This method checks given number according Luhn algorithm. * * @static * @access private * @param string $number to be validated * @return bool true if number is valid, false otherwise * @link http://en.wikipedia.org/wiki/Luhn_algorithm */ function _mod10($number) { // Double every second digit started at the right $doubledNumber = ""; $odd = false; for($i = strlen($number)-1; $i >=0; $i--) { $doubledNumber .= ($odd) ? $number[$i]*2 : $number[$i]; $odd = !$odd; } // Add up each 'single' digit $sum = 0; for($i = 0; $i < strlen($doubledNumber); $i++) { $sum += (int)$doubledNumber[$i]; } // A valid number doesn't have a remainder after mod10 or equal to 0 return (($sum % 10 == 0) && ($sum != 0)) ? true : false; } // }}} } // }}} ?> http://cvs.php.net/viewvc.cgi/pear/Validate/package_FI.xml?view=markup&rev=1.1 Index: pear/Validate/package_FI.xml +++ pear/Validate/package_FI.xml <?xml version="1.0" encoding="UTF-8"?> <package packagerversion="1.4.11" 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_FI</name> <channel>pear.php.net</channel> <summary>Validation class for Finland</summary> <description>Package containes locale validation for Finland such as: * Postal Code * Telephone Number * Car License Plate Number * Motorbike License Plate Number * Personal Identity Number (HETU) * Unique Identification Number (SATU) * Business ID Number (Y-tunnus) * Party Identification Number (OVT-tunnus) * Value Added Tax Number (ALV-numero) * Bank Account Number (tilinumero) * Bank Reference Number (viitenumero) * Credit Card Number </description> <lead> <name>Jani Mikkonen</name> <user>janisto</user> <email>jani@mikkonen.info</email> <active>yes</active> </lead> <date>2006-11-08</date> <version> <release>0.2.0</release> <api>0.2.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license> <notes> - BC break: Renamed carReg() to carLicensePlate() - BC break: Renamed bikeReg() to bikeLicensePlate() - BC break: pin() retuns array containing gender and date of birth if optional param is true - Fixed some typos and rewrote parts of the code - Added unit tests for all public methods - Proper API documentation - Change package.xml to version 2 - Removed str_pad extension requirement (typo) </notes> <contents> <dir name="/"> <file name="Validate/FI.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file name="tests/validate_FI_postalCode.phpt" role="test" /> <file name="tests/validate_FI_phoneNumber.phpt" role="test" /> <file name="tests/validate_FI_carLicensePlate.phpt" role="test" /> <file name="tests/validate_FI_bikeLicensePlate.phpt" role="test" /> <file name="tests/validate_FI_pin.phpt" role="test" /> <file name="tests/validate_FI_finuid.phpt" role="test" /> <file name="tests/validate_FI_businessId.phpt" role="test" /> <file name="tests/validate_FI_partyId.phpt" role="test" /> <file name="tests/validate_FI_vatNumber.phpt" role="test" /> <file name="tests/validate_FI_bankAccount.phpt" role="test" /> <file name="tests/validate_FI_refNum.phpt" role="test" /> <file name="tests/validate_FI_creditCard.phpt" role="test" /> <file name="LICENSE" role="doc" /> </dir> </contents> <dependencies> <required> <php> <min>4.0.1</min> </php> <pearinstaller> <min>1.4.0</min> </pearinstaller> </required> </dependencies> <phprelease /> <changelog> <release> <version> <release>0.2.0</release> <api>0.2.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2006-11-08</date> <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license> <notes> - BC break: Renamed carReg() to carLicensePlate() - BC break: Renamed bikeReg() to bikeLicensePlate() - BC break: pin() retuns array containing gender and date of birth if optional param is true - Fixed some typos and rewrote parts of the code - Added unit tests for all public methods - Proper API documentation - Change package.xml to version 2 - Removed str_pad extension requirement (typo) </notes> </release> <release> <version> <release>0.1.0</release> <api>0.1.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2006-10-26</date> <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license> <notes> - Initial release </notes> </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_bankAccount.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_bankAccount.phpt +++ pear/Validate/tests/validate_FI_bankAccount.phpt --TEST-- validate_FI_bankAccount.phpt: Unit tests for bankAccount method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_bankAccount.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $bankAccounts = array('159030-776', // OK '12345-1', // NOK '12345-12345', // NOK '123456-1', // NOK '123456-123456789', // NOK '159030-6776', // NOK '759030-776', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest bankAccount\n"; foreach ($bankAccounts as $bankAccount) { echo "{$bankAccount}: ".$noYes[Validate_FI::bankAccount($bankAccount)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test bankAccount 159030-776: YES 12345-1: NO 12345-12345: NO 123456-1: NO 123456-123456789: NO 159030-6776: NO 759030-776: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_bikeLicensePlate.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_bikeLicensePlate.phpt +++ pear/Validate/tests/validate_FI_bikeLicensePlate.phpt --TEST-- validate_FI_bikeLicensePlate.phpt: Unit tests for bikeLicensePlate method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_bikeLicensePlate.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $bikeLicensePlates = array('AB123', // OK 'ABC123', // OK 'AB1', // OK 'ABC12', // OK 'AB1234', // NOK 'A123', // NOK '123123', // NOK '1212', // NOK 'abc123', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest bikeLicensePlate\n"; foreach ($bikeLicensePlates as $bikeLicensePlate) { echo "{$bikeLicensePlate}: ".$noYes[Validate_FI::bikeLicensePlate($bikeLicensePlate)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test bikeLicensePlate AB123: YES ABC123: YES AB1: YES ABC12: YES AB1234: NO A123: NO 123123: NO 1212: NO abc123: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_businessId.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_businessId.phpt +++ pear/Validate/tests/validate_FI_businessId.phpt --TEST-- validate_FI_businessId.phpt: Unit tests for businessId method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_businessId.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $businessIds = array('1572860-0', // OK '0737546-2', // OK '0737546-1', // NOK '0737546-11', // NOK '0737545-2', // NOK '57286XX-0', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest businessId\n"; foreach ($businessIds as $businessId) { echo "{$businessId}: ".$noYes[Validate_FI::businessId($businessId)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test businessId 1572860-0: YES 0737546-2: YES 0737546-1: NO 0737546-11: NO 0737545-2: NO 57286XX-0: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_carLicensePlate.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_carLicensePlate.phpt +++ pear/Validate/tests/validate_FI_carLicensePlate.phpt --TEST-- validate_FI_carLicensePlate.phpt: Unit tests for carLicensePlate method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_carLicensePlate.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $carLicensePlates = array('AB-123', // OK 'ABC-123', // OK 'AB-1', // OK 'ABC-12', // OK 'AB-1234', // NOK 'A-123', // NOK '123-123', // NOK '12-12', // NOK 'abc-123', // NOK 'CD-1234', // OK 'C-12345', // OK 'CD-12', // OK 'C-12', // OK 'C-1', // OK 'D-123', // NOK 'C-123456', // NOK 'CD-12345', // NOK 'cd-1234', // NOK 'c-12345', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest carLicensePlate\n"; foreach ($carLicensePlates as $carLicensePlate) { echo "{$carLicensePlate}: ".$noYes[Validate_FI::carLicensePlate($carLicensePlate)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test carLicensePlate AB-123: YES ABC-123: YES AB-1: YES ABC-12: YES AB-1234: NO A-123: NO 123-123: NO 12-12: NO abc-123: NO CD-1234: YES C-12345: YES CD-12: YES C-12: YES C-1: YES D-123: NO C-123456: NO CD-12345: NO cd-1234: NO c-12345: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_creditCard.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_creditCard.phpt +++ pear/Validate/tests/validate_FI_creditCard.phpt --TEST-- validate_FI_creditCard.phpt: Unit tests for creditCard method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_creditCard.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $creditCards = array('5427 0073 1297 6425', // OK '5427007312976425', // OK '4929 9474 1842 2442', // OK '4929947418422442', // OK '346 2488 5493 9558', // OK '346248854939558', // OK '30 2942 7659 2881', // OK '30294276592881', // OK '6762195515061814', // NOK '0x1A6A195515061813', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest creditCard\n"; foreach ($creditCards as $creditCard) { echo "{$creditCard}: ".$noYes[Validate_FI::creditCard($creditCard)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test creditCard 5427 0073 1297 6425: YES 5427007312976425: YES 4929 9474 1842 2442: YES 4929947418422442: YES 346 2488 5493 9558: YES 346248854939558: YES 30 2942 7659 2881: YES 30294276592881: YES 6762195515061814: NO 0x1A6A195515061813: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_finuid.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_finuid.phpt +++ pear/Validate/tests/validate_FI_finuid.phpt --TEST-- validate_FI_finuid.phpt: Unit tests for finuid method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_finuid.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $finuids = array('10011187H', // OK '10011188H', // NOK '100X1187H', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest finuid\n"; foreach ($finuids as $finuid) { echo "{$finuid}: ".$noYes[Validate_FI::finuid($finuid)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test finuid 10011187H: YES 10011188H: NO 100X1187H: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_partyId.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_partyId.phpt +++ pear/Validate/tests/validate_FI_partyId.phpt --TEST-- validate_FI_partyId.phpt: Unit tests for partyId method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_partyId.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $partyIds = array('003715728600', // OK '003707375462', // OK '003707375464', // NOK '003607375462', // NOK '003707375452', // NOK '003757286XX0', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest partyId\n"; foreach ($partyIds as $partyId) { echo "{$partyId}: ".$noYes[Validate_FI::partyId($partyId)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test partyId 003715728600: YES 003707375462: YES 003707375464: NO 003607375462: NO 003707375452: NO 003757286XX0: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_phoneNumber.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_phoneNumber.phpt +++ pear/Validate/tests/validate_FI_phoneNumber.phpt --TEST-- validate_FI_phoneNumber.phpt: Unit tests for phoneNumber method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_phoneNumber.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $phoneNumbers = array('+358 50 1234567', // OK '+358 9 1234 567', // OK '00358 9 1234 567', // OK '050 1234567', // OK '050 1234 567', // OK '040-1234567', // OK '(09) 1234567', // OK '(09) 1234 567', // OK '+358 50 123456789123456789', // NOK '12', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest phoneNumber\n"; foreach ($phoneNumbers as $phoneNumber) { echo "{$phoneNumber}: ".$noYes[Validate_FI::phoneNumber($phoneNumber)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test phoneNumber +358 50 1234567: YES +358 9 1234 567: YES 00358 9 1234 567: YES 050 1234567: YES 050 1234 567: YES 040-1234567: YES (09) 1234567: YES (09) 1234 567: YES +358 50 123456789123456789: NO 12: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_pin.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_pin.phpt +++ pear/Validate/tests/validate_FI_pin.phpt --TEST-- validate_FI_pin.phpt: Unit tests for pin method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_pin.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $pins = array('010101-123N', // OK '010101-123J', // NOK '310201-123U', // NOK, date is not valid 'ABC123', // NOK '123456789', // NOK 'abcdef-123N', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest pin\n"; foreach ($pins as $pin) { echo "{$pin}: ".$noYes[Validate_FI::pin($pin)]."\n"; } echo "\nTest pin with optional param\n"; foreach ($pins as $pin) { if($test = Validate_FI::pin($pin, true)) { echo "{$pin}: YES\n"; print_r($test); } else { echo "{$pin}: NO\n"; } } ?> --EXPECT-- Test Validate_FI **************** Test pin 010101-123N: YES 010101-123J: NO 310201-123U: NO ABC123: NO 123456789: NO abcdef-123N: NO 0: NO -1: NO valid: NO Test pin with optional param 010101-123N: YES Array ( [0] => Male [1] => 1901-01-01 ) 010101-123J: NO 310201-123U: NO ABC123: NO 123456789: NO abcdef-123N: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_postalCode.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_postalCode.phpt +++ pear/Validate/tests/validate_FI_postalCode.phpt --TEST-- validate_FI_postalCode.phpt: Unit tests for postalCode method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_postalCode.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $postalCodes = array('00100', // OK '0010', // NOK '001000', // NOK '99999', // OK, it's actually the postal code for Santa Claus :) '99X99', // NOK 'fin-12345', // NOK 'fin-1234', // NOK 'FIN-12345', // NOK 'FIN-1234', // NOK 'fi-12345', // NOK 'fi-1234', // NOK 'FI-12345', // OK 'FI-1234', // NOK 'FI-00100', // OK 'FI-123456', // NOK 'FI00100', // NOK '-12345', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest postalCode\n"; foreach ($postalCodes as $postalCode) { echo "{$postalCode}: ".$noYes[Validate_FI::postalCode($postalCode)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test postalCode 00100: YES 0010: NO 001000: NO 99999: YES 99X99: NO fin-12345: NO fin-1234: NO FIN-12345: NO FIN-1234: NO fi-12345: NO fi-1234: NO FI-12345: YES FI-1234: NO FI-00100: YES FI-123456: NO FI00100: NO -12345: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_refNum.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_refNum.phpt +++ pear/Validate/tests/validate_FI_refNum.phpt --TEST-- validate_FI_refNum.phpt: Unit tests for refNum method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_refNum.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $refNums = array('61 74354', // OK '6174354', // OK '123', // NOK '1234512345123451234512345', // NOK '12345 54321 123', // NOK '987 78934 83947', // NOK '345948365887635', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest refNum\n"; foreach ($refNums as $refNum) { echo "{$refNum}: ".$noYes[Validate_FI::refNum($refNum)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test refNum 61 74354: YES 6174354: YES 123: NO 1234512345123451234512345: NO 12345 54321 123: YES 987 78934 83947: NO 345948365887635: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_vatNumber.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_vatNumber.phpt +++ pear/Validate/tests/validate_FI_vatNumber.phpt --TEST-- validate_FI_vatNumber.phpt: Unit tests for vatNumber method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_vatNumber.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $vatNumbers = array('FI15728600', // OK 'FI07375462', // OK 'IF15728600', // NOK 'FI15728602', // NOK '003715728600', // NOK 'FI57286XX0', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest vatNumber\n"; foreach ($vatNumbers as $vatNumber) { echo "{$vatNumber}: ".$noYes[Validate_FI::vatNumber($vatNumber)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test vatNumber FI15728600: YES FI07375462: YES IF15728600: NO FI15728602: NO 003715728600: NO FI57286XX0: NO 0: NO -1: NO valid: NO
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/FI.php?view=markup&rev=1.1 Index: pear/Validate/Validate/FI.php +++ pear/Validate/Validate/FI.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ // +----------------------------------------------------------------------+ // | Copyright (c) 2006 Jani Mikkonen | // +----------------------------------------------------------------------+ // | 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 BSD license 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. | // +----------------------------------------------------------------------+ // | Author: Jani Mikkonen <jani@mikkonen.info> | // +----------------------------------------------------------------------+ // /** * Specific validation methods for data used in Finland * * @category Validate * @package Validate_FI * @author Jani Mikkonen <jani@mikkonen.info> * @copyright 2006 Jani Mikkonen * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: FI.php,v 1.1 2007/03/23 08:54:10 janisto Exp $ * @link http://pear.php.net/package/Validate_FI */ // {{{ class Validate_FI /** * Validation class for Finland * * This class provides methods to validate: * - Postal Code * - Telephone Number * - Car License Plate Number * - Motorbike License Plate Number * - Personal Identity Number (HETU) * - Unique Identification Number (SATU) * - Business ID Number (Y-tunnus) * - Party Identification Number (OVT-tunnus) * - Value Added Tax Number (ALV-numero) * - Bank Account Number (tilinumero) * - Bank Reference Number (viitenumero) * - Credit Card Number * * @category Validate * @package Validate_FI * @author Jani Mikkonen <jani@mikkonen.info> * @copyright 2006 Jani Mikkonen * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version Release: @package_version@ * @link http://pear.php.net/package/Validate_FI */ class Validate_FI { // {{{ bool Validate_FI::postalCode( string $number [, bool $strong = false] ) /** * Validate Finnish postal code. * * Five digit postal code, maybe with a leading 'FI-'. * * Format: XXXXX or FI-XXXXX * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $postalCode = '00100'; * if ( Validate_FI::postalCode($postalCode) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the postal code to be validated * @param bool optional; strong checks * (e.g. against a list of postal codes) * @return bool true if postal code is valid, false otherwise */ function postalCode($number, $strong=false) { return (preg_match("/^(FI-)?[0-9]{5}$/", $number)) ? true : false; } // }}} // {{{ bool Validate_FI::phoneNumber( string $number ) /** * Validate Finnish telephone number. * * Simple check: number must be numeric when (, ), -, +, ., ' ' * chars are removed and 3-20 digit number. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $phoneNumber = '+358 40 1234567'; * if ( Validate_FI::phoneNumber($phoneNumber) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the telephone number to be validated * @return bool true if telephone number is valid, false otherwise */ function phoneNumber($number){ $number = str_replace(Array('(', ')', '-', '+', '.', ' '), '', $number); return (preg_match("/^[0-9]{3,20}$/", $number)) ? true : false; } // }}} // {{{ bool Validate_FI::carLicensePlate( string $number ) /** * Validate Finnish car license plate number. * * Format: AAA-XXX, CD-XXXX or C-XXXXX * * AAA-XXX: AAA is 2-3 letters UPPERCASE A-Z and XXX is 1-3 numbers * CD-XXXX: CD- and XXXX is 1-4 numbers (diplomat licence plate) * C-XXXXX: C- and XXXXX is 1-5 numbers (other tax-free diplomat licence plate) * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $carLicensePlate = 'ABC-123'; * if ( Validate_FI::carLicensePlate($carLicensePlate) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the license plate number to be validated * @return bool true if license plate number is valid, false otherwise * @link http://www.ake.fi/AKE/Rekisterointi/Suomen_rekisterikilvet/ */ function carLicensePlate($number){ // diplomat licence plate if (preg_match("/^CD-[0-9]{1,4}$/", $number)) { return true; } // other tax-free diplomat licence plate if (preg_match("/^C-[0-9]{1,5}$/", $number)) { return true; } // regular licence plate if (preg_match("/^[A-Z]{2,3}-[0-9]{1,3}$/", $number)) { return true; } return false; } // }}} // {{{ bool Validate_FI::bikeLicensePlate( string $number ) /** * Validate Finnish motorbike license plate number. * * Format: AAAXXX * * Where AAA is 2-3 letters UPPERCASE A-Z and XXX is 1-3 numbers. * Letters and numbers are actually in separate lines. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $bikeLicensePlate = 'ABC123'; * if ( Validate_FI::bikeLicensePlate($bikeLicensePlate) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number the license plate number to be validated * @return bool true if license plate number is valid, false otherwise * @link http://www.ake.fi/AKE/Rekisterointi/Suomen_rekisterikilvet/ */ function bikeLicensePlate($number){ return (preg_match("/^[A-Z]{2,3}(\n)?[0-9]{1,3}$/", $number)) ? true : false; } // }}} // {{{ mixed Validate_FI::pin( string $number [, bool $info = false] ) /** * Validate Personal Identity Number (HETU). * * The Finnish PIN number (HETU) aka Social Security Number (SSN) * is a 11 digit number with birthdate as ddmmyycxxxy where c is century, * xxx is a three digit individual number and the last digit is a * control number (y). * * If xxx is odd it's a male PIN number and if even a female. * * Return gender (Male or Female) and date of birth (YYYY-MM-DD) in array if * PIN is valid, is available by switching $info (2nd parameter) to true. * * Example: 010101-123N would be a male and born in 1st of January 1901. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $pin = '010101-123N'; * if ( Validate_FI::pin($pin) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * if ( $userinfo = Validate_FI::pin($pin, true) ) { * print_r($userinfo); * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number PIN number to be validated * @param bool optional; Return gender and date of birth on success * @return mixed Returns true or false if $info = false or * gender (Male or Female) and date of birth (YYYY-MM-DD) * in array if PIN is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#hetu1 */ function pin($number, $info = false) { $pin = strtoupper($number); static $control = array("0","1","2","3","4","5","6","7","8","9", "A","B","C","D","E","F","H","J","K","L", "M","N","P","R","S","T","U","V","W","X","Y"); static $century = array('+' => "18", '-' => "19", 'A' => "20"); if(ereg("^([0-9]{2})([0-9]{2})([0-9]{2})([+-A]{1})([0-9]{3})([0-9A-Z]{1})$",$pin,$regs)) { // Validate date of birth. Must be a Gregorian date. if(checkdate($regs[2],$regs[1],$century[$regs[4]].$regs[3])) { if($control[intval($regs[1].$regs[2].$regs[3].$regs[5])%31] == $regs[6]) { if($info) { $gen = ($regs[5]%2==1) ? 'Male' : 'Female'; $dob = $century[$regs[4]].$regs[3].'-'.$regs[2].'-'.$regs[1]; return array($gen, $dob); } else { return true; } } } } return false; } // }}} // {{{ bool Validate_FI::finuid( string $number ) /** * Validate Finnish Unique Identification Number (SATU). * * FINUID (SATU) is a 9 digit number. The last digit is a control number. * * Example: 10011187H * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $finuid = '10011187H'; * if ( Validate_FI::finuid($finuid) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number FINUID number to be validated * @return bool true if FINUID is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#satu */ function finuid($number) { $number = strtoupper($number); static $control = array("0","1","2","3","4","5","6","7","8","9", "A","B","C","D","E","F","H","J","K","L", "M","N","P","R","S","T","U","V","W","X","Y"); if(ereg("^([0-9]{8})([0-9A-Z]{1})$",$number,$regs)) { if($control[intval($regs[1])%31] == $regs[2]) { return true; } } return false; } // }}} // {{{ bool Validate_FI::businessId( string $number ) /** * Validate Finnish Business ID (Y-tunnus). * * The Finnish Business ID number (Y-tunnus) is a 9 digit number. * The last digit is a control number (y). * * Format: xxxxxxx-y * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $businessId = '1572860-0'; * if ( Validate_FI::businessId($businessId) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number Business ID number to be validated * @return bool true if Business ID is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#y-tunnus2 */ function businessId($number) { if (preg_match("/^[0-9]{6,7}-[0-9]{1}$/", $number)) { list($num, $control) = split('[-]', $number); // Add leading zeros if number is < 7 $num = str_pad($num, 7, 0, STR_PAD_LEFT); $controlSum = 0; $controlSum += (int)substr($num, 0, 1)*7; $controlSum += (int)substr($num, 1, 1)*9; $controlSum += (int)substr($num, 2, 1)*10; $controlSum += (int)substr($num, 3, 1)*5; $controlSum += (int)substr($num, 4, 1)*8; $controlSum += (int)substr($num, 5, 1)*4; $controlSum += (int)substr($num, 6, 1)*2; $controlSum = $controlSum%11; if($controlSum == 0) { return ($controlSum == $control) ? true : false; } else if($controlSum >= 2 && $controlSum <= 10 ) { return ((11 - $controlSum) == $control) ? true : false; } } return false; } // }}} // {{{ bool Validate_FI::partyId( int $number ) /** * Validate Finnish Party Identification number (OVT-tunnus). * * The Finnish Party Identification number (OVT-tunnus) is a 12-17 * digit number and it is generated from Business ID. * * Example: 0037AAAAAAAABBBBB, 0037 indicates Finland, AAAAAAAA is the * Business ID and BBBBB is optional organization number. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $partyId = '003715728600'; * if ( Validate_FI::partyId($partyId) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param int $number Party Identification number to be validated * @return bool true if number is valid, false otherwise * @see Validate_FI::businessId() * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#alv-numero */ function partyId($number) { if (preg_match("/^[0-9]{12,17}$/", $number)) { $countryCode = substr($number, 0, 4); $controlNum = substr($number, 11, 1); $businessNum = substr($number, 4, 7); $businessId = $businessNum.'-'.$controlNum; if($countryCode == '0037' && Validate_FI::businessId($businessId)) { return true; } } return false; } // }}} // {{{ bool Validate_FI::vatNumber( string $number ) /** * Validate Finnish Value Added Tax number (ALV-numero). * * The Finnish VAT number (ALV-numero) is maximum * of 14 digits and is generated from Business ID. * * Format: FIXXXXXXXX * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $vatNumber = 'FI15728600'; * if ( Validate_FI::vatNumber($vatNumber) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number VAT number to be validated * @return bool true if VAT number is valid, false otherwise * @see Validate_FI::businessId() * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#alv-numero */ function vatNumber($number) { $countryCode = substr($number, 0, 2); $controlNum = substr($number, -1, 1); $businessNum = substr($number, 2, -1); $businessId = $businessNum.'-'.$controlNum; if($countryCode == 'FI' && Validate_FI::businessId($businessId)) { return true; } return false; } // }}} // {{{ bool Validate_FI::bankAccount( string $number ) /** * Validate Finnish bank account number. * * This method checks the bank account number according to * Finnish Bank Association. * * Format: XXXXXX-XXXXXXXX, 6 digits, - and 2-8 digits. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $bankAccount = '159030-776'; * if ( Validate_FI::bankAccount($bankAccount) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number Finnish bank account number to be validated * @return bool true if bank account is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#pankkitili * @link http://www.pankkiyhdistys.fi/sisalto/upload/pdf/tilinrorakenne.pdf */ function bankAccount($number) { if (preg_match("/^[0-9]{6}-[0-9]{2,8}$/", $number)) { // Bank groups are identified by the first digit $bankType = substr($number, 0, 1); // Group 1: First digit is 1, 2, 3, 6 or 8 $bankGroup1 = array('1','2','3','6','8'); // Group 2: First digit is 4 or 5 $bankGroup2 = array('4','5'); // split account number ereg("([0-9]{6})-([0-9]{2,8})", $number, $regs); if (in_array($bankType, $bankGroup1)) { // Group 1: 999999-99999 -> 999999-00099999 $number = $regs[1] . str_pad($regs[2], 8, 0, STR_PAD_LEFT); // Group 2: 999999-99999 -> 999999-90009999 } else if (in_array($bankType, $bankGroup2)) { $number = $regs[1] . substr($regs[2], 0, 1) . str_pad(substr($regs[2], 1, 7), 7, 0, STR_PAD_LEFT); } // Now when we have a 14 digit bank account number, we can validate it. return Validate_FI::_mod10($number); } return false; } // }}} // {{{ bool Validate_FI::refNum( string $number ) /** * Validate Finnish bank reference number. * * This method checks the bank reference number according to * Finnish Bank Association. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $refNum = '61 74354'; * if ( Validate_FI::refNum($refNum) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number Finnish bank reference number to be validated (spaces and dashes tolerated) * @return bool true if reference number is valid, false otherwise * @link http://koti.mbnet.fi/~thales/tarkmerk.htm#viitenumero */ function refNum($number) { // Remove non-numeric characters from $refnum. Only 4-20 digit number. $refnum = ereg_replace('[^0-9]+', '', $number); // The last digit is a control number. $controlNum = substr($refnum, -1, 1); // Subtract control number from the $refnum. $refNumCheck = substr($refnum, 0, strlen($refnum)-1); if(preg_match("/^[0-9]{3,19}$/", $refNumCheck)) { // remove leading zeros $refNumCheck = ltrim($refNumCheck, 0); $mul = 7; $refSum = 0; for($refLength = strlen($refNumCheck); $refLength > 0; $refLength--) { $refSum += substr($refNumCheck, $refLength - 1, 1) * $mul; switch ($mul) { case 7: $mul = 3; break; case 3: $mul = 1; break; case 1: $mul = 7; break; } } $refSum = substr(10 - ($refSum % 10), -1); if($refSum == $controlNum){ return true; } } return false; } // }}} // {{{ bool Validate_FI::creditCard( string $number ) /** * Validate credit card number. * * This method checks the credit card number according to Luhn algorithm. * This method doesn't guarantee that the card is legitimate. * * <code> * <?php * // Include the package * require_once('Validate/FI.php'); * * $creditCard = '5427 0073 1297 6425'; * if ( Validate_FI::creditCard($creditCard) ) { * print 'Valid'; * } else { * print 'Not valid!'; * } * * ?> * </code> * * @static * @access public * @param string $number credit card number to be validated * (spaces and dashes tolerated) * @return bool true if credit card number is valid, false otherwise */ function creditCard($number) { // Remove non-numeric characters from $number $number = ereg_replace('[^0-9]+', '', $number); // Validate number return Validate_FI::_mod10($number); } // }}} // {{{ bool Validate_FI::_mod10( string $number ) /** * Validate number according to Luhn algorithm (mod 10). * * This method checks given number according Luhn algorithm. * * @static * @access private * @param string $number to be validated * @return bool true if number is valid, false otherwise * @link http://en.wikipedia.org/wiki/Luhn_algorithm */ function _mod10($number) { // Double every second digit started at the right $doubledNumber = ""; $odd = false; for($i = strlen($number)-1; $i >=0; $i--) { $doubledNumber .= ($odd) ? $number[$i]*2 : $number[$i]; $odd = !$odd; } // Add up each 'single' digit $sum = 0; for($i = 0; $i < strlen($doubledNumber); $i++) { $sum += (int)$doubledNumber[$i]; } // A valid number doesn't have a remainder after mod10 or equal to 0 return (($sum % 10 == 0) && ($sum != 0)) ? true : false; } // }}} } // }}} ?> http://cvs.php.net/viewvc.cgi/pear/Validate/package_FI.xml?view=markup&rev=1.1 Index: pear/Validate/package_FI.xml +++ pear/Validate/package_FI.xml <?xml version="1.0" encoding="UTF-8"?> <package packagerversion="1.4.11" 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_FI</name> <channel>pear.php.net</channel> <summary>Validation class for Finland</summary> <description>Package containes locale validation for Finland such as: * Postal Code * Telephone Number * Car License Plate Number * Motorbike License Plate Number * Personal Identity Number (HETU) * Unique Identification Number (SATU) * Business ID Number (Y-tunnus) * Party Identification Number (OVT-tunnus) * Value Added Tax Number (ALV-numero) * Bank Account Number (tilinumero) * Bank Reference Number (viitenumero) * Credit Card Number </description> <lead> <name>Jani Mikkonen</name> <user>janisto</user> <email>jani@mikkonen.info</email> <active>yes</active> </lead> <date>2006-11-08</date> <version> <release>0.2.0</release> <api>0.2.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license> <notes> - BC break: Renamed carReg() to carLicensePlate() - BC break: Renamed bikeReg() to bikeLicensePlate() - BC break: pin() retuns array containing gender and date of birth if optional param is true - Fixed some typos and rewrote parts of the code - Added unit tests for all public methods - Proper API documentation - Change package.xml to version 2 - Removed str_pad extension requirement (typo) </notes> <contents> <dir name="/"> <file name="Validate/FI.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file name="tests/validate_FI_postalCode.phpt" role="test" /> <file name="tests/validate_FI_phoneNumber.phpt" role="test" /> <file name="tests/validate_FI_carLicensePlate.phpt" role="test" /> <file name="tests/validate_FI_bikeLicensePlate.phpt" role="test" /> <file name="tests/validate_FI_pin.phpt" role="test" /> <file name="tests/validate_FI_finuid.phpt" role="test" /> <file name="tests/validate_FI_businessId.phpt" role="test" /> <file name="tests/validate_FI_partyId.phpt" role="test" /> <file name="tests/validate_FI_vatNumber.phpt" role="test" /> <file name="tests/validate_FI_bankAccount.phpt" role="test" /> <file name="tests/validate_FI_refNum.phpt" role="test" /> <file name="tests/validate_FI_creditCard.phpt" role="test" /> <file name="LICENSE" role="doc" /> </dir> </contents> <dependencies> <required> <php> <min>4.0.1</min> </php> <pearinstaller> <min>1.4.0</min> </pearinstaller> </required> </dependencies> <phprelease /> <changelog> <release> <version> <release>0.2.0</release> <api>0.2.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2006-11-08</date> <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license> <notes> - BC break: Renamed carReg() to carLicensePlate() - BC break: Renamed bikeReg() to bikeLicensePlate() - BC break: pin() retuns array containing gender and date of birth if optional param is true - Fixed some typos and rewrote parts of the code - Added unit tests for all public methods - Proper API documentation - Change package.xml to version 2 - Removed str_pad extension requirement (typo) </notes> </release> <release> <version> <release>0.1.0</release> <api>0.1.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2006-10-26</date> <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license> <notes> - Initial release </notes> </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_bankAccount.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_bankAccount.phpt +++ pear/Validate/tests/validate_FI_bankAccount.phpt --TEST-- validate_FI_bankAccount.phpt: Unit tests for bankAccount method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_bankAccount.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $bankAccounts = array('159030-776', // OK '12345-1', // NOK '12345-12345', // NOK '123456-1', // NOK '123456-123456789', // NOK '159030-6776', // NOK '759030-776', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest bankAccount\n"; foreach ($bankAccounts as $bankAccount) { echo "{$bankAccount}: ".$noYes[Validate_FI::bankAccount($bankAccount)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test bankAccount 159030-776: YES 12345-1: NO 12345-12345: NO 123456-1: NO 123456-123456789: NO 159030-6776: NO 759030-776: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_bikeLicensePlate.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_bikeLicensePlate.phpt +++ pear/Validate/tests/validate_FI_bikeLicensePlate.phpt --TEST-- validate_FI_bikeLicensePlate.phpt: Unit tests for bikeLicensePlate method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_bikeLicensePlate.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $bikeLicensePlates = array('AB123', // OK 'ABC123', // OK 'AB1', // OK 'ABC12', // OK 'AB1234', // NOK 'A123', // NOK '123123', // NOK '1212', // NOK 'abc123', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest bikeLicensePlate\n"; foreach ($bikeLicensePlates as $bikeLicensePlate) { echo "{$bikeLicensePlate}: ".$noYes[Validate_FI::bikeLicensePlate($bikeLicensePlate)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test bikeLicensePlate AB123: YES ABC123: YES AB1: YES ABC12: YES AB1234: NO A123: NO 123123: NO 1212: NO abc123: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_businessId.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_businessId.phpt +++ pear/Validate/tests/validate_FI_businessId.phpt --TEST-- validate_FI_businessId.phpt: Unit tests for businessId method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_businessId.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $businessIds = array('1572860-0', // OK '0737546-2', // OK '0737546-1', // NOK '0737546-11', // NOK '0737545-2', // NOK '57286XX-0', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest businessId\n"; foreach ($businessIds as $businessId) { echo "{$businessId}: ".$noYes[Validate_FI::businessId($businessId)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test businessId 1572860-0: YES 0737546-2: YES 0737546-1: NO 0737546-11: NO 0737545-2: NO 57286XX-0: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_carLicensePlate.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_carLicensePlate.phpt +++ pear/Validate/tests/validate_FI_carLicensePlate.phpt --TEST-- validate_FI_carLicensePlate.phpt: Unit tests for carLicensePlate method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_carLicensePlate.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $carLicensePlates = array('AB-123', // OK 'ABC-123', // OK 'AB-1', // OK 'ABC-12', // OK 'AB-1234', // NOK 'A-123', // NOK '123-123', // NOK '12-12', // NOK 'abc-123', // NOK 'CD-1234', // OK 'C-12345', // OK 'CD-12', // OK 'C-12', // OK 'C-1', // OK 'D-123', // NOK 'C-123456', // NOK 'CD-12345', // NOK 'cd-1234', // NOK 'c-12345', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest carLicensePlate\n"; foreach ($carLicensePlates as $carLicensePlate) { echo "{$carLicensePlate}: ".$noYes[Validate_FI::carLicensePlate($carLicensePlate)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test carLicensePlate AB-123: YES ABC-123: YES AB-1: YES ABC-12: YES AB-1234: NO A-123: NO 123-123: NO 12-12: NO abc-123: NO CD-1234: YES C-12345: YES CD-12: YES C-12: YES C-1: YES D-123: NO C-123456: NO CD-12345: NO cd-1234: NO c-12345: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_creditCard.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_creditCard.phpt +++ pear/Validate/tests/validate_FI_creditCard.phpt --TEST-- validate_FI_creditCard.phpt: Unit tests for creditCard method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_creditCard.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $creditCards = array('5427 0073 1297 6425', // OK '5427007312976425', // OK '4929 9474 1842 2442', // OK '4929947418422442', // OK '346 2488 5493 9558', // OK '346248854939558', // OK '30 2942 7659 2881', // OK '30294276592881', // OK '6762195515061814', // NOK '0x1A6A195515061813', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest creditCard\n"; foreach ($creditCards as $creditCard) { echo "{$creditCard}: ".$noYes[Validate_FI::creditCard($creditCard)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test creditCard 5427 0073 1297 6425: YES 5427007312976425: YES 4929 9474 1842 2442: YES 4929947418422442: YES 346 2488 5493 9558: YES 346248854939558: YES 30 2942 7659 2881: YES 30294276592881: YES 6762195515061814: NO 0x1A6A195515061813: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_finuid.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_finuid.phpt +++ pear/Validate/tests/validate_FI_finuid.phpt --TEST-- validate_FI_finuid.phpt: Unit tests for finuid method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_finuid.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $finuids = array('10011187H', // OK '10011188H', // NOK '100X1187H', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest finuid\n"; foreach ($finuids as $finuid) { echo "{$finuid}: ".$noYes[Validate_FI::finuid($finuid)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test finuid 10011187H: YES 10011188H: NO 100X1187H: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_partyId.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_partyId.phpt +++ pear/Validate/tests/validate_FI_partyId.phpt --TEST-- validate_FI_partyId.phpt: Unit tests for partyId method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_partyId.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $partyIds = array('003715728600', // OK '003707375462', // OK '003707375464', // NOK '003607375462', // NOK '003707375452', // NOK '003757286XX0', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest partyId\n"; foreach ($partyIds as $partyId) { echo "{$partyId}: ".$noYes[Validate_FI::partyId($partyId)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test partyId 003715728600: YES 003707375462: YES 003707375464: NO 003607375462: NO 003707375452: NO 003757286XX0: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_phoneNumber.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_phoneNumber.phpt +++ pear/Validate/tests/validate_FI_phoneNumber.phpt --TEST-- validate_FI_phoneNumber.phpt: Unit tests for phoneNumber method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_phoneNumber.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $phoneNumbers = array('+358 50 1234567', // OK '+358 9 1234 567', // OK '00358 9 1234 567', // OK '050 1234567', // OK '050 1234 567', // OK '040-1234567', // OK '(09) 1234567', // OK '(09) 1234 567', // OK '+358 50 123456789123456789', // NOK '12', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest phoneNumber\n"; foreach ($phoneNumbers as $phoneNumber) { echo "{$phoneNumber}: ".$noYes[Validate_FI::phoneNumber($phoneNumber)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test phoneNumber +358 50 1234567: YES +358 9 1234 567: YES 00358 9 1234 567: YES 050 1234567: YES 050 1234 567: YES 040-1234567: YES (09) 1234567: YES (09) 1234 567: YES +358 50 123456789123456789: NO 12: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_pin.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_pin.phpt +++ pear/Validate/tests/validate_FI_pin.phpt --TEST-- validate_FI_pin.phpt: Unit tests for pin method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_pin.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $pins = array('010101-123N', // OK '010101-123J', // NOK '310201-123U', // NOK, date is not valid 'ABC123', // NOK '123456789', // NOK 'abcdef-123N', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest pin\n"; foreach ($pins as $pin) { echo "{$pin}: ".$noYes[Validate_FI::pin($pin)]."\n"; } echo "\nTest pin with optional param\n"; foreach ($pins as $pin) { if($test = Validate_FI::pin($pin, true)) { echo "{$pin}: YES\n"; print_r($test); } else { echo "{$pin}: NO\n"; } } ?> --EXPECT-- Test Validate_FI **************** Test pin 010101-123N: YES 010101-123J: NO 310201-123U: NO ABC123: NO 123456789: NO abcdef-123N: NO 0: NO -1: NO valid: NO Test pin with optional param 010101-123N: YES Array ( [0] => Male [1] => 1901-01-01 ) 010101-123J: NO 310201-123U: NO ABC123: NO 123456789: NO abcdef-123N: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_postalCode.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_postalCode.phpt +++ pear/Validate/tests/validate_FI_postalCode.phpt --TEST-- validate_FI_postalCode.phpt: Unit tests for postalCode method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_postalCode.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $postalCodes = array('00100', // OK '0010', // NOK '001000', // NOK '99999', // OK, it's actually the postal code for Santa Claus :) '99X99', // NOK 'fin-12345', // NOK 'fin-1234', // NOK 'FIN-12345', // NOK 'FIN-1234', // NOK 'fi-12345', // NOK 'fi-1234', // NOK 'FI-12345', // OK 'FI-1234', // NOK 'FI-00100', // OK 'FI-123456', // NOK 'FI00100', // NOK '-12345', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest postalCode\n"; foreach ($postalCodes as $postalCode) { echo "{$postalCode}: ".$noYes[Validate_FI::postalCode($postalCode)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test postalCode 00100: YES 0010: NO 001000: NO 99999: YES 99X99: NO fin-12345: NO fin-1234: NO FIN-12345: NO FIN-1234: NO fi-12345: NO fi-1234: NO FI-12345: YES FI-1234: NO FI-00100: YES FI-123456: NO FI00100: NO -12345: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_refNum.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_refNum.phpt +++ pear/Validate/tests/validate_FI_refNum.phpt --TEST-- validate_FI_refNum.phpt: Unit tests for refNum method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_refNum.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $refNums = array('61 74354', // OK '6174354', // OK '123', // NOK '1234512345123451234512345', // NOK '12345 54321 123', // NOK '987 78934 83947', // NOK '345948365887635', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest refNum\n"; foreach ($refNums as $refNum) { echo "{$refNum}: ".$noYes[Validate_FI::refNum($refNum)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test refNum 61 74354: YES 6174354: YES 123: NO 1234512345123451234512345: NO 12345 54321 123: YES 987 78934 83947: NO 345948365887635: NO 0: NO -1: NO valid: NO http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_FI_vatNumber.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_FI_vatNumber.phpt +++ pear/Validate/tests/validate_FI_vatNumber.phpt --TEST-- validate_FI_vatNumber.phpt: Unit tests for vatNumber method 'Validate/FI.php' --FILE-- <?php // $Id: validate_FI_vatNumber.phpt,v 1.1 2007/03/23 08:54:10 janisto Exp $ // Validate test script $noYes = array('NO', 'YES'); require_once 'Validate/FI.php'; echo "Test Validate_FI\n"; echo "****************\n"; $vatNumbers = array('FI15728600', // OK 'FI07375462', // OK 'IF15728600', // NOK 'FI15728602', // NOK '003715728600', // NOK 'FI57286XX0', // NOK '0', // NOK '-1', // NOK 'valid' // NOK ); echo "\nTest vatNumber\n"; foreach ($vatNumbers as $vatNumber) { echo "{$vatNumber}: ".$noYes[Validate_FI::vatNumber($vatNumber)]."\n"; } ?> --EXPECT-- Test Validate_FI **************** Test vatNumber FI15728600: YES FI07375462: YES IF15728600: NO FI15728602: NO 003715728600: NO FI57286XX0: NO 0: NO -1: NO valid: NO