diff --git a/Validate/UK.php b/Validate/UK.php deleted file mode 100644 index 85b53a3..0000000 --- a/Validate/UK.php +++ /dev/null @@ -1,242 +0,0 @@ - - * @author Ian P. Christian - * @author Tomas V.V.Cox - * @author Pierre-Alain Joye - * @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$ - * @link http://pear.php.net/package/Validate_UK - */ - -/** - * Data validation class for the UK - * - * This class provides methods to validate: - * - SSN (National Insurance/NI Number) - * - Sort code - * - Bank account number - * - Postal code - * - Telephone number - * - Car registration number - * - Passport - * - Driving license - * - * @category Validate - * @package Validate_UK - * @author Michael Dransfield - * @author Ian P. Christian - * @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 -{ - /** - * validates a postcode - * - * Validation according to the "UK Government Data Standards Catalogue" - * Using PostCode-format version 2.1, which can be obtained from: - * http://www.govtalk.gov.uk/gdsc/html/noframes/PostCode-2-1-Release.htm - * - * Note: The official validation-pattern was altered to also support postcodes - * with none or even spaces at various places. We don't count spaces as being - * "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 - * @return bool - */ - function postalCode($postcode, $strong = false) - { - // $strong is not used here at the moment; added for API compatibility - // checks might be added at a later stage - - // 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; - return $match; - } - - /** - * Validates a social security number whic in UK is - * National Insurance Number or ni for short - * - * Validation according to the "UK Government Data Standards Catalogue" - * Using NationalInsuranceNumber-format version 2.1, which can be obtained from: - * 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. - * - * @param string $ssn NI number - * - * @access public - * @return bool - */ - function ssn($ssn) - { - // remove spaces and uppercase it - $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'); - return (array_search(substr($ssn, 0, 2), $bad_prefixes) === false); - } - return false; - } - - /** - * Validates a sort code, must be passed with dashes in the right places - * - * @param string $sc the sort code - * - * @access public - * @return bool - * @see - */ - function sortCode($sc) - { - // 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}$/"; - $match = (preg_match($preg, $sc)) ? true : false; - return $match; - } - - /** - * Validates a bank ac number - * - * do not use - it is too basic at the moment - * - * @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 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; - } - - /** - * Checks that the entry is a number starting with 0 of the right length - * - * @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); - return $number[0] == 0 // first number is 0 - && (($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))); - } - - /** - * Validates a car registration number - * - * @param string $reg the registration number - * - * @access public - * @return bool - */ - function carReg($reg) - { - include_once 'Validate/UK/carReg.php'; - $reg = strtoupper(str_replace(array('-', ' '), '', $reg)); - // functions to check, in order - $regFuncs = array( - '2001', - '1982', - '1963', - '1950', - '1932', - 'Pre1932' - ); - foreach ($regFuncs as $func) { - $cfunc = 'validateVehicle' . $func; - $ret = $cfunc($reg); - if ($ret !== false) { - // maybe return something useful here when possible? - return true; - } - } - return false; - } - - /** - * Validates a UK passport number. - * - * EU might be the same just checks for 9 digits - * - * @param string $pp the passport number - * - * @access public - * @return string - */ - function passport($pp) - { - // just checks for 9 digit number - return (ctype_digit($pp) && strlen($pp) == 9); - } - - /** - * Validates a UK driving licence - * - * @param string $dl the driving license - * - * @access public - * @return bool - */ - function drive($dl) - { - $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; - } -} -?> diff --git a/Validate/UK/carReg.php b/Validate/UK/carReg.php deleted file mode 100644 index 7359f90..0000000 --- a/Validate/UK/carReg.php +++ /dev/null @@ -1,320 +0,0 @@ - - * @author Ian P. Christian - * @author Tomas V.V.Cox - * @author Pierre-Alain Joye - * @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$ - * @link http://pear.php.net/package/Validate_UK - */ - - -/** - * 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)) { - // invalidly formed - return false; - } -} - -/** - * validateVehicle1932 - * - * @param string $input car reg - * - * @access public - * @return bool - */ -function validateVehicle1932($input) -{ - if (!preg_match('/^[A-Z]{3}\d{1,3}$/', $input, $m)) { - // invalidly formed - return false; - } -} - -/** - * 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)) { - // invalidly formed - return false; - } -} - -/** - * 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)) { - // invalidly formed - return false; - } -} - -/** - * 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)) { - // invalidly formed - return false; - } - $year = ord($m[1]) - 65; - if ($year > 15) { - // two letters per year - $year -= floor(($year - 15) / 2); - } - $year += 1984; - // 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; - for ($i = count($region['dvla']); $i--;) { - if (strpos($region['dvla'][$i], $m[1][1]) !== false) { - $dvla = $region['dvla'][$i]; - break; - } - } - if ($dvla === false) { - // dvla office can't be found - return false; - } - $cur_month = date('n'); - if ($m[2] > 50) { - $m[2] -= 50; - } - if ($cur_month < 3) { - $m[2]++; - } - if ($m[2] < 1) { - // invalid year - return false; - } - $year = 2000 + $m[2]; - if (strpbrk($m[3], 'IQ') !== false) { - // invalid suffix - return false; - } - return array( - 'region' => $region['region'], - 'year' => 2000 + $m[2], - 'dvla' => $dvla - ); -} - -// source: http://en.wikipedia.org/wiki/British_car_number_plate_identifiers -$regions2001 = array( - 'A' => array( - 'region' => 'East Anglia', - 'dvla' => array( - 'ABCDEFGHJKLMN' => 'Peterborough', - 'OPRSTU' => 'Norwich', - 'VWXY' => 'Ipswich' - ) - ), - 'B' => array( - 'region' => 'Birmingham', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Birmingham' - ) - ), - 'C' => array( - 'region' => 'Cymru', - 'dvla' => array( - 'ABCDEFGHJKLMNO' => 'Cardiff', - 'PRSTUV' => 'Swansea', - 'WXY' => 'Bangor' - ) - ), - 'D' => array( - 'region' => 'Deeside etc.', - 'dvla' => array( - 'ABCDEFGHJK' => 'Chester', - 'LMNOPRSTUVWXY' => 'Shrewsbury' - ) - ), - 'E' => array( - 'region' => 'Essex and Hertfordshire', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Chelmsford' - ) - ), - 'F' => array( - 'region' => 'Forest and Ferns', - 'dvla' => array( - 'ABCDEFGHJKLMNOP' => 'Nottingham', - 'RSTUVWXY' => 'Lincoln' - ) - ), - 'G' => array( - 'region' => 'Garden of England', - 'dvla' => array( - 'ABCDEFGHJKLMNO' => 'Maidstone', - 'PRSTUVWXY' => 'Brighton' - ) - ), - 'H' => array( - 'region' => 'Hants and Dorset', - 'dvla' => array( - 'ABCDEFGHJ' => 'Bournemouth', - 'KLMNOPRSTUVWXY' => 'Portsmouth' - ) - ), - 'K' => array( - 'region' => '', - 'dvla' => array( - 'ABCDEFGHJKL' => 'Luton', - 'MNOPRSTUVWXY' => 'Northampton' - ) - ), - 'L' => array( - 'region' => 'London', - 'dvla' => array( - 'ABCDEFGHJ' => 'Wimbledon', - 'KLMNOPRST' => 'Standmore', - 'UVWXY' => 'Sidcup' - ) - ), - 'M' => array( - 'region' => 'Manchester and Merseyside', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Manchester' - ) - ), - 'N' => array( - 'region' => 'Newcastle and North', - 'dvla' => array( - 'ABCDEFGHJKLMNO' => 'Newcastle upon Tyne', - 'PRSTUVWXY' => 'Stockton-on-Tees' - ) - ), - 'O' => array( - 'region' => 'Oxford', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Oxford' - ) - ), - 'P' => array( - 'region' => 'Preston and Pennines', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRST' => 'Preston', - 'UVWXY' => 'Carlisle' - ) - ), - 'Q' => array( - 'region' => 'Oxford', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Any - used for vehicles of unidentifiable age' - ) - ), - 'R' => array( - 'region' => 'Reading', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Reading' - ) - ), - 'S' => array( - 'region' => 'Scotland', - 'dvla' => array( - 'ABCDEFGHJ' => 'Glasgow', - 'KLMNO' => 'Edinburgh', - 'PRST' => 'Dundee', - 'UVW' => 'Aberdeen', - 'XY' => 'Inverness' - ) - ), - 'V' => array( - 'region' => 'Vale of Severn', - 'dvla' => array( - 'ABCDEFGHJKLMNOPRSTUVWXY' => 'Worcester' - ) - ), - 'W' => array( - 'region' => 'West Country', - 'dvla' => array( - 'ABCDEFGHJ' => 'Exeter', - 'KL' => 'Truro', - 'MNOPRSTUVWXY' => 'Bristol' - ) - ), - 'Y' => array( - 'region' => 'Yorkshire', - 'dvla' => array( - 'ABCDEFGHJK' => 'Leeds', - 'LMNOPRSTU' => 'Sheffield', - 'VWXY' => 'Beverley' - ) - ) -); - -?> diff --git a/package_UK.xml b/package_UK.xml deleted file mode 100644 index f707fda..0000000 --- a/package_UK.xml +++ /dev/null @@ -1,130 +0,0 @@ - - - Validate_UK - pear.php.net - Validation class for UK - Package containes locale validation for UK such as: - * SSN (National Insurance/IN) - * Postal Code - * Sort Code - * Bank AC - * Telephone numbers - * Car registration numbers - * Passports - * Driver license - - - - Arpad Ray - arpad - arpad@php.net - yes - - - Ian P. Christian - pookey - pookey@php.net - yes - - 2007-03-27 - - - 0.5.4 - 0.5.4 - - - alpha - alpha - - New BSD - -QA release -Bug #12149 package doesn't install carReg.php -Bug #12148 there are a number of coding standard bugs in the package (49errors/19warnings) -Bug #11670 phoneNumber does not validate correctly sometimes. -Bug #9242 Error in telephone checking - - - - - - - - - - - - - - - - - - - 4.2.0 - - - 1.4.0b1 - - - - - - - - 0.5.2 - 0.5.2 - - - alpha - alpha - - 2005-04-17 - New BSD - Attention, this release has a BC break: -- tel renamed to phoneNumber to confirm to the Validate standard -- faster regexp for the postal code - - - - - - 0.5.1 - 0.5.1 - - - alpha - alpha - - 2005-10-01 - New BSD - - Switch to the new BSD License -(see http://www.opensource.org/licenses/bsd-license.php) - - - - - - 0.5.0 - 0.5.0 - - - alpha - alpha - - 2005-05-20 - New BSD - - Split from Validate into independent package -- CS fixes -- BC break! -postalCode unified between countries (name wise), now all postcode validation funcs are named postalCode -ni was renamed to ssn to keep it the same in all classes -- getZipValFunc removed - - - - - diff --git a/tests/bug14535.phpt b/tests/bug14535.phpt deleted file mode 100644 index d9e236e..0000000 --- a/tests/bug14535.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -bug_14535.phpt: Unit tests for bug 14535; last digit of UK SSN doesn't allow a space ---FILE-- - ---EXPECT-- -Test Bug 14535 -**************** -Test ssn -JM 40 24 25 C: YES -JM56765F: NO -JM567645T: NO -JM567645R: NO -JM567645D: YES -BG567645D: NO -NA123456 : YES diff --git a/tests/validate_UK.phpt b/tests/validate_UK.phpt deleted file mode 100644 index 1ad4274..0000000 --- a/tests/validate_UK.phpt +++ /dev/null @@ -1,238 +0,0 @@ ---TEST-- -validate_UK.phpt: Unit tests for United Kingdom Validation class ---FILE-- - ---EXPECT-- -Test Validate_UK -**************** -Test postalCode -BS25 1NB: YES -B5 5TF: YES -5Ty6tty: NO -3454545: NO -SW1 4RT: YES -SW1A 4RT: YES -BS45678TH: NO -BF 3RT: NO -M1 1AA: YES -M60 1NW: YES -CR2 6XH: YES -DN55 1PT: YES -W1A 1HQ: YES -EC1A 1BB: YES -GIR 0AA: YES -V1 1AA: NO -M6L 1NW: NO -CJ2 6XH: NO -QN55 1PT: NO -W1L 1HQ: NO -EC1A 1BC: NO -GIR 1AA: NO -CF23 7JN: YES -BS8 4UD: YES -GU19 5AT: YES -CF11 6TA: YES -SW1A 1AA: YES -NW9 0EQ: YES -AB12C 1AA: NO -B12D 3XY: NO -Q1 5AT: NO -BI10 4UD: NO - -Test ssn -JM 40 24 25 C: YES -JM56765F: NO -JM567645T: NO -JM567645R: NO -JM567645D: YES -BG567645D: NO - -Test sortCode -09-01-24: YES -345676: NO -0-78-56: NO -21-68-78: YES -foo21-68-78: NO -21-68-78bar: NO -34-234-56: NO - -Test tel -02012345678: YES -020-1234-5678: YES -020 1234 5678: YES -000 1234 5678: NO -020 1234 56789: NO -020 1234 567: NO -foo020 1234 5678: NO -020 1234 5678bar: NO - -Test bankAC -01234567: YES -012345678: NO -foo01234567: NO -01234567bar: NO -foobar: NO - -Test drive -ABCDE012345ABCDE: YES -ABCDEE012345ABCDE: NO -ABCDE012345ABCD: NO -fooABCDE012345ABCDE: NO -ABCDE012345ABCDEbar: NO - -Car registrations -A 123 ABC: YES -S7 VEN: YES -ABC 123 A: YES -A1: YES -123 ABC: NO -11: NO -AA: NO -AA 51 ABCDE: NO -: NO