Source for file UK.php
Documentation is available at UK.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Specific validation methods for data used in the UK
* This source file is subject to the New BSD license, That is bundled
* with this package in the file LICENSE, and is available through
* 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 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 243194 2007-09-29 23:23:34Z kguest $
* @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)
* - Car registration number
* @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
* 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)
// $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
$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;
* 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
* for the validation-process.
* @param string $ssn NI number
// remove spaces and uppercase it
$preg = "/^[A-CEGHJ-NOPR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[ABCD]?$/";
$bad_prefixes = array ('GB', 'BG', 'NK', 'KN', 'TN', 'NT', 'ZZ');
* Validates a sort code, must be passed with dashes in the right places
* @param string $sc the sort code
// 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}$/";
* Validates a bank ac number
* do not use - it is too basic at the moment
* @param string $ac the account number
// 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}$/";
* Checks that the entry is a number starting with 0 of the right length
* @param string $number the tel number
//phone number can't include letters.
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
include_once 'Validate/UK/carReg.php';
// functions to check, in order
foreach ($regFuncs as $func) {
$cfunc = 'validateVehicle' . $func;
// maybe return something useful here when possible?
* Validates a UK passport number.
* EU might be the same just checks for 9 digits
* @param string $pp the passport number
// just checks for 9 digit number
* Validates a UK driving licence
* @param string $dl the driving license
$preg = "/^[A-Z]{5}[0-9]{6}[A-Z0-9]{5}$/";
Documentation generated on Sun, 10 Oct 2010 14:30:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|