cvs: pear /Validate/Validate UK.php /Validate/Validate/UK carReg.php /Validate/tests validate_UK.phpt
| From: | Ken Guest | Date: | Sat, 29 Sep 2007 23:23:34 +0000 |
| Subject: | cvs: pear /Validate/Validate UK.php /Validate/Validate/UK carReg.php /Validate/tests validate_UK.phpt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-48713@lists.php.net to get a copy of this message | ||
kguest Sat Sep 29 23:23:34 2007 UTC
Modified files:
/pear/Validate/Validate UK.php
/pear/Validate/Validate/UK carReg.php
/pear/Validate/tests validate_UK.phpt
Log:
Bug #12148 there are a number of coding standard bugs in the package (49errors/19warnings)
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/UK.php?r1=1.28&r2=1.29&diff_format=u Index: pear/Validate/Validate/UK.php diff -u pear/Validate/Validate/UK.php:1.28 pear/Validate/Validate/UK.php:1.29 --- pear/Validate/Validate/UK.php:1.28 Sat Apr 21 13:27:27 2007 +++ pear/Validate/Validate/UK.php Sat Sep 29 23:23:34 2007 @@ -1,32 +1,28 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Michael Dransfield, Pierre-Alain Joye, | -// | Ian P. Christian | -// +----------------------------------------------------------------------+ -// | 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. | -// +----------------------------------------------------------------------+ -// | Author: Tomas V.V.Cox <cox@idecnet.com> | -// | Pierre-Alain Joye <pajoye@php.net> | -// +----------------------------------------------------------------------+ -// /** * Specific validation methods for data used in the UK * - * @category Validate - * @package Validate_UK - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @author Ian P. Christian <pookey@pookey.co.uk> - * @copyright 1997-2005 Michael Dransfield, Ian P. Christian - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: UK.php,v 1.28 2007/04/21 13:27:27 arpad Exp $ - * @link http://pear.php.net/package/Validate_UK + * 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_UK + * @author Michael Dransfield <mikeNO@SPAMblueroot.net> + * @author Ian P. Christian <pookey@pookey.co.uk> + * @author Tomas V.V.Cox <cox@idecnet.com> + * @author Pierre-Alain Joye <pajoye@php.net> + * @copyright 1997-2005 Michael Dransfield, Ian P. Christian, Pierre-Alain Joye + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: UK.php,v 1.29 2007/09/29 23:23:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_UK */ /** @@ -42,14 +38,14 @@ * - Passport * - Driving license * - * @category Validate - * @package Validate_UK - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @author Ian P. Christian <pookey@pookey.co.uk> - * @copyright 1997-2005 Michael Dransfield, Ian P. Christian - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_UK + * @category Validate + * @package Validate_UK + * @author Michael Dransfield <mikeNO@SPAMblueroot.net> + * @author Ian P. Christian <pookey@pookey.co.uk> + * @copyright 1997-2005 Michael Dransfield, Ian P. Christian + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_UK */ class Validate_UK { @@ -65,9 +61,11 @@ * "essential" for the validation-process. * It was also necessary to refactor the regex to make it usable for preg_match. * + * @param string $postcode the postcode to be validated + * @param bool $strong optional; strong checks (e.g. against a list + * of postcodes) (not implanted) + * * @access public - * @param string the postcode to be validated - * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool */ function postalCode($postcode, $strong = false) @@ -77,8 +75,9 @@ // remove spaces and uppercase it $postcode = strtoupper(str_replace(' ', '', $postcode)); - $preg = "/^([A-PR-UWYZ]([0-9]([0-9]|[A-HJKSTUW])?|[A-HK-Y][0-9]([0-9]|[ABEHMNPRVWXY])?)[0-9][ABD-HJLNP-UW-Z]{2}|GIR0AA)$/"; - $match = preg_match($preg, $postcode) ? true : false; + $preg = "/^([A-PR-UWYZ]([0-9]([0-9]|[A-HJKSTUW])?|[A-HK-Y][0-9]" + . "([0-9]|[ABEHMNPRVWXY])?)[0-9][ABD-HJLNP-UW-Z]{2}|GIR0AA)$/"; + $match = preg_match($preg, $postcode) ? true : false; return $match; } @@ -88,21 +87,22 @@ * * Validation according to the "UK Government Data Standards Catalogue" * Using NationalInsuranceNumber-format version 2.1, which can be obtained from: - * http://www.govtalk.gov.uk/gdsc/html/noframes/NationalInsuranceNumber-2-1-Release.htm + * www.govtalk.gov.uk/gdsc/html/noframes/NationalInsuranceNumber-2-1-Release.htm * * Note: The official validation-pattern was altered to also support numbers * with none or even spaces at various places. We don't count spaces as being * "essential" * for the validation-process. * - * @access public - * @param string $ssn NI number - * @return bool + * @param string $ssn NI number + * + * @access public + * @return bool */ function ssn($ssn) { // remove spaces and uppercase it - $ssn = strtoupper(str_replace(' ', '', $ssn)); + $ssn = strtoupper(str_replace(' ', '', $ssn)); $preg = "/^[A-CEGHJ-NOPR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[ABCD]?$/"; if (preg_match($preg, $ssn)) { $bad_prefixes = array('GB', 'BG', 'NK', 'KN', 'TN', 'NT', 'ZZ'); @@ -114,10 +114,10 @@ /** * Validates a sort code, must be passed with dashes in the right places * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $sc the sort code - * @return bool + * @param string $sc the sort code + * + * @access public + * @return bool * @see */ function sortCode($sc) @@ -125,27 +125,29 @@ // must be in format nn-nn-nn (must contain dashes) // need to research the range of values - i have assumed 00-00-00 to 99-99-99 // but it might be something like 01-01-01 to 50-99-99 - $preg = "/^[0-9]{2}\-[0-9]{2}\-[0-9]{2}$/"; + $preg = "/^[0-9]{2}\-[0-9]{2}\-[0-9]{2}$/"; $match = (preg_match($preg, $sc)) ? true : false; return $match; } /** * Validates a bank ac number + * * do not use - it is too basic at the moment * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $ac - * @return bool + * @param string $ac the account number + * + * @access public + * @return bool */ function bankAC($ac) { // just checking to see if it is 6-8 digits // FIXME *THIS IS PROBABLY WRONG!!! RESEARCH* - // There is a modulus 10/11 system that could be implmeneted here, but it's potentially quite - // complex - http://en.wikipedia.org/wiki/Luhn_formula - Ian - $preg = "/^[0-9]{6,8}$/"; + // There is a modulus 10/11 system that could be implemented here, but + // it's potentially quite complex + // http://en.wikipedia.org/wiki/Luhn_formula - Ian + $preg = "/^[0-9]{6,8}$/"; $match = (preg_match($preg, $ac)) ? true : false; return $match; } @@ -153,18 +155,22 @@ /** * Checks that the entry is a number starting with 0 of the right length * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $number the tel number - * @return bool + * @param string $number the tel number + * + * @access public + * @return bool * @see */ function phoneNumber($number) { + //phone number can't include letters. + if (preg_match("/[A-Z]/i", $number) != 0) { + return false; + } $number = preg_replace('/\D+/', '', $number); - $len = strlen($number); + $len = strlen($number); return $number[0] == 0 // first number is 0 - && ($len == 11 // 11 digits is fine + && (($len == 11 && ($number[1] != "0")) // 11 digits is fine || ($len == 10 // 10 digits is fine if 01 or 08 && ($number[1] == 1 || $number[1] == 8))); } @@ -172,14 +178,14 @@ /** * Validates a car registration number * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $reg the registration number - * @return bool + * @param string $reg the registration number + * + * @access public + * @return bool */ function carReg($reg) { - require_once 'Validate/UK/carReg.php'; + include_once 'Validate/UK/carReg.php'; $reg = strtoupper(str_replace(array('-', ' '), '', $reg)); // functions to check, in order $regFuncs = array( @@ -192,7 +198,7 @@ ); foreach ($regFuncs as $func) { $cfunc = 'validateVehicle' . $func; - $ret = $cfunc($reg); + $ret = $cfunc($reg); if ($ret !== false) { // maybe return something useful here when possible? return true; @@ -202,15 +208,14 @@ } /** + * Validates a UK passport number. * - * Validates a UK passport number, EU might be the same - * just checks for 9 digits + * EU might be the same just checks for 9 digits * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $ - * @param string $name - * @return string + * @param string $pp the passport number + * + * @access public + * @return string */ function passport($pp) { @@ -221,19 +226,17 @@ /** * Validates a UK driving licence * + * @param string $dl the driving license * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $dl - * @return bool + * @access public + * @return bool */ function drive($dl) { - $dl = strtoupper(str_replace(' ', '', $dl)); - $preg = "/^[A-Z]{5}[0-9]{6}[A-Z0-9]{5}$/"; + $dl = strtoupper(str_replace(' ', '', $dl)); + $preg = "/^[A-Z]{5}[0-9]{6}[A-Z0-9]{5}$/"; $match = (preg_match($preg, $dl)) ? true : false; return $match; } } - ?> http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/UK/carReg.php?r1=1.1&r2=1.2&diff_format=u Index: pear/Validate/Validate/UK/carReg.php diff -u pear/Validate/Validate/UK/carReg.php:1.1 pear/Validate/Validate/UK/carReg.php:1.2 --- pear/Validate/Validate/UK/carReg.php:1.1 Sat Nov 26 13:57:22 2005 +++ pear/Validate/Validate/UK/carReg.php Sat Sep 29 23:23:34 2007 @@ -1,7 +1,41 @@ <?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/** + * Specific validation methods for data used in the UK + * + * 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_UK + * @author Michael Dransfield <mikeNO@SPAMblueroot.net> + * @author Ian P. Christian <pookey@pookey.co.uk> + * @author Tomas V.V.Cox <cox@idecnet.com> + * @author Pierre-Alain Joye <pajoye@php.net> + * @copyright 1997-2005 Michael Dransfield, Ian P. Christian, Pierre-Alain Joye + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: carReg.php,v 1.2 2007/09/29 23:23:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_UK + */ -// input must be uppercased and spaces and dashes removed +/** + * validateVehiclePre1932 + * + * input must be uppercased and spaces and dashes removed + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehiclePre1932($input) { if (!preg_match('/^[A-Z]{1,2}\d{1,4}$/', $input, $m)) { @@ -10,6 +44,14 @@ } } +/** + * validateVehicle1932 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1932($input) { if (!preg_match('/^[A-Z]{3}\d{1,3}$/', $input, $m)) { @@ -18,6 +60,14 @@ } } +/** + * validateVehicle1950 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1950($input) { if (!preg_match('/^\d{1,3}[A-Z]{3}\d{1,4}[A-Z]{1,3}$/', $input, $m)) { @@ -26,6 +76,14 @@ } } +/** + * validateVehicle1963 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1963($input) { if (!preg_match('/^([A-Z]{3})\d{1,3}([A-Z]?)$/', $input, $m)) { @@ -34,6 +92,14 @@ } } +/** + * validateVehicle1982 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1982($input) { if (!preg_match('/^([A-Z])\d{1,3}[A-Z]{3}$/', $input, $m)) { @@ -46,25 +112,33 @@ $year -= floor(($year - 15) / 2); } $year += 1984; - // is there a region list anywhere? + // is there a region list anywhere? return array( 'year' => $year ); } +/** + * validateVehicle2001 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle2001($input) { if (!preg_match('/^([A-Z]{2})(\d{2})([A-Z]{3})$/', $input, $m)) { // invalidly formed return false; - } + } global $regions2001; if (!isset($regions2001[$m[1][0]])) { // region can't be found return false; } $region = $regions2001[$m[1]]; - $dvla = false; + $dvla = false; for ($i = count($region['dvla']); $i--;) { if (strpos($region['dvla'][$i], $m[1][1]) !== false) { $dvla = $region['dvla'][$i]; http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_UK.phpt?r1=1.6&r2=1.7&diff_format=u Index: pear/Validate/tests/validate_UK.phpt diff -u pear/Validate/tests/validate_UK.phpt:1.6 pear/Validate/tests/validate_UK.phpt:1.7 --- pear/Validate/tests/validate_UK.phpt:1.6 Sat Jul 21 17:37:31 2007 +++ pear/Validate/tests/validate_UK.phpt Sat Sep 29 23:23:34 2007 @@ -2,10 +2,15 @@ validate_UK.phpt: Unit tests for United Kingdom Validation class --FILE-- <?php -// $Id: validate_UK.phpt,v 1.6 2007/07/21 17:37:31 moosh Exp $ +// $Id: validate_UK.phpt,v 1.7 2007/09/29 23:23:34 kguest Exp $ // Validate test script $noYes = array('NO', 'YES'); -require 'Validate/UK.php'; +if (is_file(dirname(__FILE__) . '/../Validate/UK.php')) { + require_once dirname(__FILE__) . '/../Validate/UK.php'; + require_once dirname(__FILE__) . '/../Validate/UK/carReg.php'; +} else { + require_once 'Validate/UK.php'; +} echo "Test Validate_UK\n"; echo "****************\n"; @@ -29,7 +34,7 @@ 'W1A 1HQ', // OK 'EC1A 1BB', // OK 'GIR 0AA', // OK - + /* some variations of the official examples which make it non-compliant */ 'V1 1AA', // NOK 'M6L 1NW', // NOK @@ -38,7 +43,7 @@ 'W1L 1HQ', // NOK 'EC1A 1BC', // NOK 'GIR 1AA', // NOK - + /* additional checks by David Grant (djg), these are valid */ 'CF23 7JN', // OK 'BS8 4UD', // OK @@ -76,7 +81,7 @@ '020-1234-5678', // OK '020 1234 5678', // OK '000 1234 5678', // NOK - '020 1234 56789', // OK + '020 1234 56789', // NOK '020 1234 567', // NOK 'foo020 1234 5678', // NOK '020 1234 5678bar', // NOK @@ -202,7 +207,7 @@ 020-1234-5678: YES 020 1234 5678: YES 000 1234 5678: NO -020 1234 56789: YES +020 1234 56789: NO 020 1234 567: NO foo020 1234 5678: NO 020 1234 5678bar: NO
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/UK.php?r1=1.28&r2=1.29&diff_format=u Index: pear/Validate/Validate/UK.php diff -u pear/Validate/Validate/UK.php:1.28 pear/Validate/Validate/UK.php:1.29 --- pear/Validate/Validate/UK.php:1.28 Sat Apr 21 13:27:27 2007 +++ pear/Validate/Validate/UK.php Sat Sep 29 23:23:34 2007 @@ -1,32 +1,28 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Michael Dransfield, Pierre-Alain Joye, | -// | Ian P. Christian | -// +----------------------------------------------------------------------+ -// | 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. | -// +----------------------------------------------------------------------+ -// | Author: Tomas V.V.Cox <cox@idecnet.com> | -// | Pierre-Alain Joye <pajoye@php.net> | -// +----------------------------------------------------------------------+ -// /** * Specific validation methods for data used in the UK * - * @category Validate - * @package Validate_UK - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @author Ian P. Christian <pookey@pookey.co.uk> - * @copyright 1997-2005 Michael Dransfield, Ian P. Christian - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: UK.php,v 1.28 2007/04/21 13:27:27 arpad Exp $ - * @link http://pear.php.net/package/Validate_UK + * 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_UK + * @author Michael Dransfield <mikeNO@SPAMblueroot.net> + * @author Ian P. Christian <pookey@pookey.co.uk> + * @author Tomas V.V.Cox <cox@idecnet.com> + * @author Pierre-Alain Joye <pajoye@php.net> + * @copyright 1997-2005 Michael Dransfield, Ian P. Christian, Pierre-Alain Joye + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: UK.php,v 1.29 2007/09/29 23:23:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_UK */ /** @@ -42,14 +38,14 @@ * - Passport * - Driving license * - * @category Validate - * @package Validate_UK - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @author Ian P. Christian <pookey@pookey.co.uk> - * @copyright 1997-2005 Michael Dransfield, Ian P. Christian - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_UK + * @category Validate + * @package Validate_UK + * @author Michael Dransfield <mikeNO@SPAMblueroot.net> + * @author Ian P. Christian <pookey@pookey.co.uk> + * @copyright 1997-2005 Michael Dransfield, Ian P. Christian + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_UK */ class Validate_UK { @@ -65,9 +61,11 @@ * "essential" for the validation-process. * It was also necessary to refactor the regex to make it usable for preg_match. * + * @param string $postcode the postcode to be validated + * @param bool $strong optional; strong checks (e.g. against a list + * of postcodes) (not implanted) + * * @access public - * @param string the postcode to be validated - * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool */ function postalCode($postcode, $strong = false) @@ -77,8 +75,9 @@ // remove spaces and uppercase it $postcode = strtoupper(str_replace(' ', '', $postcode)); - $preg = "/^([A-PR-UWYZ]([0-9]([0-9]|[A-HJKSTUW])?|[A-HK-Y][0-9]([0-9]|[ABEHMNPRVWXY])?)[0-9][ABD-HJLNP-UW-Z]{2}|GIR0AA)$/"; - $match = preg_match($preg, $postcode) ? true : false; + $preg = "/^([A-PR-UWYZ]([0-9]([0-9]|[A-HJKSTUW])?|[A-HK-Y][0-9]" + . "([0-9]|[ABEHMNPRVWXY])?)[0-9][ABD-HJLNP-UW-Z]{2}|GIR0AA)$/"; + $match = preg_match($preg, $postcode) ? true : false; return $match; } @@ -88,21 +87,22 @@ * * Validation according to the "UK Government Data Standards Catalogue" * Using NationalInsuranceNumber-format version 2.1, which can be obtained from: - * http://www.govtalk.gov.uk/gdsc/html/noframes/NationalInsuranceNumber-2-1-Release.htm + * www.govtalk.gov.uk/gdsc/html/noframes/NationalInsuranceNumber-2-1-Release.htm * * Note: The official validation-pattern was altered to also support numbers * with none or even spaces at various places. We don't count spaces as being * "essential" * for the validation-process. * - * @access public - * @param string $ssn NI number - * @return bool + * @param string $ssn NI number + * + * @access public + * @return bool */ function ssn($ssn) { // remove spaces and uppercase it - $ssn = strtoupper(str_replace(' ', '', $ssn)); + $ssn = strtoupper(str_replace(' ', '', $ssn)); $preg = "/^[A-CEGHJ-NOPR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[ABCD]?$/"; if (preg_match($preg, $ssn)) { $bad_prefixes = array('GB', 'BG', 'NK', 'KN', 'TN', 'NT', 'ZZ'); @@ -114,10 +114,10 @@ /** * Validates a sort code, must be passed with dashes in the right places * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $sc the sort code - * @return bool + * @param string $sc the sort code + * + * @access public + * @return bool * @see */ function sortCode($sc) @@ -125,27 +125,29 @@ // must be in format nn-nn-nn (must contain dashes) // need to research the range of values - i have assumed 00-00-00 to 99-99-99 // but it might be something like 01-01-01 to 50-99-99 - $preg = "/^[0-9]{2}\-[0-9]{2}\-[0-9]{2}$/"; + $preg = "/^[0-9]{2}\-[0-9]{2}\-[0-9]{2}$/"; $match = (preg_match($preg, $sc)) ? true : false; return $match; } /** * Validates a bank ac number + * * do not use - it is too basic at the moment * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $ac - * @return bool + * @param string $ac the account number + * + * @access public + * @return bool */ function bankAC($ac) { // just checking to see if it is 6-8 digits // FIXME *THIS IS PROBABLY WRONG!!! RESEARCH* - // There is a modulus 10/11 system that could be implmeneted here, but it's potentially quite - // complex - http://en.wikipedia.org/wiki/Luhn_formula - Ian - $preg = "/^[0-9]{6,8}$/"; + // There is a modulus 10/11 system that could be implemented here, but + // it's potentially quite complex + // http://en.wikipedia.org/wiki/Luhn_formula - Ian + $preg = "/^[0-9]{6,8}$/"; $match = (preg_match($preg, $ac)) ? true : false; return $match; } @@ -153,18 +155,22 @@ /** * Checks that the entry is a number starting with 0 of the right length * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $number the tel number - * @return bool + * @param string $number the tel number + * + * @access public + * @return bool * @see */ function phoneNumber($number) { + //phone number can't include letters. + if (preg_match("/[A-Z]/i", $number) != 0) { + return false; + } $number = preg_replace('/\D+/', '', $number); - $len = strlen($number); + $len = strlen($number); return $number[0] == 0 // first number is 0 - && ($len == 11 // 11 digits is fine + && (($len == 11 && ($number[1] != "0")) // 11 digits is fine || ($len == 10 // 10 digits is fine if 01 or 08 && ($number[1] == 1 || $number[1] == 8))); } @@ -172,14 +178,14 @@ /** * Validates a car registration number * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $reg the registration number - * @return bool + * @param string $reg the registration number + * + * @access public + * @return bool */ function carReg($reg) { - require_once 'Validate/UK/carReg.php'; + include_once 'Validate/UK/carReg.php'; $reg = strtoupper(str_replace(array('-', ' '), '', $reg)); // functions to check, in order $regFuncs = array( @@ -192,7 +198,7 @@ ); foreach ($regFuncs as $func) { $cfunc = 'validateVehicle' . $func; - $ret = $cfunc($reg); + $ret = $cfunc($reg); if ($ret !== false) { // maybe return something useful here when possible? return true; @@ -202,15 +208,14 @@ } /** + * Validates a UK passport number. * - * Validates a UK passport number, EU might be the same - * just checks for 9 digits + * EU might be the same just checks for 9 digits * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $ - * @param string $name - * @return string + * @param string $pp the passport number + * + * @access public + * @return string */ function passport($pp) { @@ -221,19 +226,17 @@ /** * Validates a UK driving licence * + * @param string $dl the driving license * - * @access public - * @author Michael Dransfield <mikeNO@SPAMblueroot.net> - * @param string $dl - * @return bool + * @access public + * @return bool */ function drive($dl) { - $dl = strtoupper(str_replace(' ', '', $dl)); - $preg = "/^[A-Z]{5}[0-9]{6}[A-Z0-9]{5}$/"; + $dl = strtoupper(str_replace(' ', '', $dl)); + $preg = "/^[A-Z]{5}[0-9]{6}[A-Z0-9]{5}$/"; $match = (preg_match($preg, $dl)) ? true : false; return $match; } } - ?> http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/UK/carReg.php?r1=1.1&r2=1.2&diff_format=u Index: pear/Validate/Validate/UK/carReg.php diff -u pear/Validate/Validate/UK/carReg.php:1.1 pear/Validate/Validate/UK/carReg.php:1.2 --- pear/Validate/Validate/UK/carReg.php:1.1 Sat Nov 26 13:57:22 2005 +++ pear/Validate/Validate/UK/carReg.php Sat Sep 29 23:23:34 2007 @@ -1,7 +1,41 @@ <?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/** + * Specific validation methods for data used in the UK + * + * 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_UK + * @author Michael Dransfield <mikeNO@SPAMblueroot.net> + * @author Ian P. Christian <pookey@pookey.co.uk> + * @author Tomas V.V.Cox <cox@idecnet.com> + * @author Pierre-Alain Joye <pajoye@php.net> + * @copyright 1997-2005 Michael Dransfield, Ian P. Christian, Pierre-Alain Joye + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: carReg.php,v 1.2 2007/09/29 23:23:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_UK + */ -// input must be uppercased and spaces and dashes removed +/** + * validateVehiclePre1932 + * + * input must be uppercased and spaces and dashes removed + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehiclePre1932($input) { if (!preg_match('/^[A-Z]{1,2}\d{1,4}$/', $input, $m)) { @@ -10,6 +44,14 @@ } } +/** + * validateVehicle1932 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1932($input) { if (!preg_match('/^[A-Z]{3}\d{1,3}$/', $input, $m)) { @@ -18,6 +60,14 @@ } } +/** + * validateVehicle1950 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1950($input) { if (!preg_match('/^\d{1,3}[A-Z]{3}\d{1,4}[A-Z]{1,3}$/', $input, $m)) { @@ -26,6 +76,14 @@ } } +/** + * validateVehicle1963 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1963($input) { if (!preg_match('/^([A-Z]{3})\d{1,3}([A-Z]?)$/', $input, $m)) { @@ -34,6 +92,14 @@ } } +/** + * validateVehicle1982 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle1982($input) { if (!preg_match('/^([A-Z])\d{1,3}[A-Z]{3}$/', $input, $m)) { @@ -46,25 +112,33 @@ $year -= floor(($year - 15) / 2); } $year += 1984; - // is there a region list anywhere? + // is there a region list anywhere? return array( 'year' => $year ); } +/** + * validateVehicle2001 + * + * @param string $input car reg + * + * @access public + * @return bool + */ function validateVehicle2001($input) { if (!preg_match('/^([A-Z]{2})(\d{2})([A-Z]{3})$/', $input, $m)) { // invalidly formed return false; - } + } global $regions2001; if (!isset($regions2001[$m[1][0]])) { // region can't be found return false; } $region = $regions2001[$m[1]]; - $dvla = false; + $dvla = false; for ($i = count($region['dvla']); $i--;) { if (strpos($region['dvla'][$i], $m[1][1]) !== false) { $dvla = $region['dvla'][$i]; http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_UK.phpt?r1=1.6&r2=1.7&diff_format=u Index: pear/Validate/tests/validate_UK.phpt diff -u pear/Validate/tests/validate_UK.phpt:1.6 pear/Validate/tests/validate_UK.phpt:1.7 --- pear/Validate/tests/validate_UK.phpt:1.6 Sat Jul 21 17:37:31 2007 +++ pear/Validate/tests/validate_UK.phpt Sat Sep 29 23:23:34 2007 @@ -2,10 +2,15 @@ validate_UK.phpt: Unit tests for United Kingdom Validation class --FILE-- <?php -// $Id: validate_UK.phpt,v 1.6 2007/07/21 17:37:31 moosh Exp $ +// $Id: validate_UK.phpt,v 1.7 2007/09/29 23:23:34 kguest Exp $ // Validate test script $noYes = array('NO', 'YES'); -require 'Validate/UK.php'; +if (is_file(dirname(__FILE__) . '/../Validate/UK.php')) { + require_once dirname(__FILE__) . '/../Validate/UK.php'; + require_once dirname(__FILE__) . '/../Validate/UK/carReg.php'; +} else { + require_once 'Validate/UK.php'; +} echo "Test Validate_UK\n"; echo "****************\n"; @@ -29,7 +34,7 @@ 'W1A 1HQ', // OK 'EC1A 1BB', // OK 'GIR 0AA', // OK - + /* some variations of the official examples which make it non-compliant */ 'V1 1AA', // NOK 'M6L 1NW', // NOK @@ -38,7 +43,7 @@ 'W1L 1HQ', // NOK 'EC1A 1BC', // NOK 'GIR 1AA', // NOK - + /* additional checks by David Grant (djg), these are valid */ 'CF23 7JN', // OK 'BS8 4UD', // OK @@ -76,7 +81,7 @@ '020-1234-5678', // OK '020 1234 5678', // OK '000 1234 5678', // NOK - '020 1234 56789', // OK + '020 1234 56789', // NOK '020 1234 567', // NOK 'foo020 1234 5678', // NOK '020 1234 5678bar', // NOK @@ -202,7 +207,7 @@ 020-1234-5678: YES 020 1234 5678: YES 000 1234 5678: NO -020 1234 56789: YES +020 1234 56789: NO 020 1234 567: NO foo020 1234 5678: NO 020 1234 5678bar: NO