Source for file IE.php
Documentation is available at IE.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Data validation class for Ireland
* 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 David Coallier <davidc@php.net>
* @copyright 1997-2008 Agora Production (http://agoraproduction.com)
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/Validate_IE
* Data validation class for Ireland
* This class provides methods to validate:
* @author David Coallier <davidc@php.net>
* @author Ken Guest <ken@linux.ie>
* @copyright 1997-2008 Agora Production (http://agoraproduction.com)
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/Validate_IE
// {{{ public function swift
* Validate an Irish SWIFT code
* @param string $swift swift code
* @return bool true if number is valid, false if not.
return preg_match('/^[a-z0-9]{4}IE[a-z0-9]{2}$/i', $swift);
// {{{ public function IBAN
* @param string $iban The account number to be validated
* @param string $swift swift code to compare against IBAN
function IBAN($iban, $swift = false )
$swift = substr($swift, 0 , 4 );
if (substr($iban, 4 , 4 ) != $swift) {
if (substr($iban, 0 , 2 ) == 'IE') {
include_once 'Validate/Finance/IBAN.php';
return Validate_Finance_IBAN ::validate ($iban);
// {{{ public function phoneNumber
* Validate an irish phone number
* This function validates an irish phone number.
* You can either use the requiredAreaCode or not.
* by default this is set to true.
* @param string $number The phone number
* @param bool $requiredAreaCode defaults to true - to require area code checks
* require_once('Validate/IE.php');
* $phoneNumber = '+353 1 213 4567';
* if ( Validate_IE::phoneNumber($phoneNumber) ) {
* $phoneNumber = '213 4567';
* if ( Validate_IE::phoneNumber($phoneNumber, false) ) {
* @return bool true if number is valid, false if not.
function phoneNumber($number, $requiredAreaCode = true )
* categorize prefixes into landline, mobile and 'other'
* each prefix has an associated regular expression.
* use defaultRegExp if associated entry is empty.
* @note Irish phone numbers are not the same as UK Phone numbers;
* Irish phone numbers are much less complex as UK now has per
* district phone numbers etc.
static $defaultRegExp = '/^\d{7,10}$/';
static $irishLandLine = array (
'21'=> '', '22'=> '', '23'=> '', '24'=> '', '25'=> '', '242'=> '',
'225'=> '', '26'=> '', '27'=> '', '28'=> '', '29'=> '', '402'=> '',
'404'=> '', '405'=> '', '41'=> '', '42'=> '', '43'=> '', '44'=> '',
'45'=> '', '46'=> '', '47'=> '',
'48'=> '/^048[0-9]{8}$/', //direct dial to Northern Ireland
'49'=> '', '51'=> '', '52'=> '', '53'=> '', '54'=> '', '55'=> '',
'505'=> '/^0505[0-9]{5}$/',
'506'=> '', '509'=> '', '61'=> '', '62'=> '', '63'=> '', '64'=> '',
'65'=> '', '66'=> '', '67'=> '', '68'=> '', '69'=> '', '71'=> '',
'818'=> '/^0818[0-9]{6}$/',
'90'=> '', '91'=> '', '92'=> '', '93'=> '', '94'=> '', '95'=> '',
'96'=> '', '97'=> '', '98'=> '', '99'=> '');
static $irishMobileAreas = array ('83'=> '/^083[0-9]{7}$/',
'89'=> '/^089[0-9]{7}$/');
static $irishMobileAreasVoiceMail = array ('83'=> '/^0835[0-9]{7}$/',
'85'=> '/^0855[0-9]{7}$/',
'86'=> '/^0865[0-9]{7}$/',
'87'=> '/^0875[0-9]{7}$/',
'88'=> '/^0885[0-9]{7}$/',
'89'=> '/^0895[0-9]{7}$/');
static $irishOtherRates = array ('1800'=> '/^1800[0-9]{6}$/',
'1850'=> '/^1850[0-9]{6}$/',
'1890'=> '/^1890[0-9]{6}$/');
if (preg_match ('/^00.*$/', $number)) {
$number = '+' . substr ($number, 2 );
$number = str_replace (array ('(', ')', '-', '+', '.', ' '), '', $number);
//remove country code for Ireland and insert leading zero of area code.
//presence of area code is implied if country code is present.
if (strpos ($number, '353') === 0 ) {
$number = "0" . substr ($number, 3 );
//area code must start with the standard 0 or a 1 for 'other rates'.
if (($requiredAreaCode) && !(preg_match("(^[01][0-9]*$)", $number))) {
//check special rate numbers
if (($requiredAreaCode) && (substr($number, 0 , 1 ) == '1')) {
$prefix = substr($number, 0 , 4 );
if (isset ($irishOtherRates[$prefix])) {
$reg = $irishOtherRates[$prefix];
//if number has ten digits and a prefix it's likely a mobile phone
if (($requiredAreaCode) && ($len == 10 )) {
$prefix = substr($number, 1 , 2 );
if (isset ($irishMobileAreas[$prefix])) {
$regexp = $irishMobileAreas[$prefix];
//see if it's a mobile phone with a 'direct to voicemail' prefix.
if (($requiredAreaCode) && ($len == 11 )) {
$prefix = substr($number, 1 , 2 );
if (isset ($irishMobileAreasVoiceMail[$prefix])) {
$regexp = $irishMobileAreasVoiceMail[$prefix];
if (!$requiredAreaCode) {
//regular numbers, without an area code, don't start with a zero.
//they may be 5-8 digits long (depending on area code which can
$preg = "/^[1-9]\d{4,7}$/";
for ($i = 3; $i > 0; $i-- ) {
$prefix = substr($number, 1 , $i);
if (isset ($irishLandLine[$prefix])) {
$preg = $irishLandLine[$prefix];
// {{{ public function postalcode
* This function validates postal district codes in Dublin.
* It will be revised when national postal codes are rolled out.
* @param string $postalCode The postal code to validate
* @param string $dir optional; /path/to/data/dir
* @link http://en.wikipedia.org/wiki/List_of_Dublin_postal_districts
* @return bool true if postcode is ok, false otherwise
if ($dir != null && (is_file($dir . '/IE_postcodes.txt'))) {
$file = $dir . '/IE_postcodes.txt';
$file = '@DATADIR@/Validate_IE/data/IE_postcodes.txt';
return in_array($postalCode, $postcodes);
// {{{ public function passport
* Validate an irish passport number.
* @param string $pp The passport number to validate.
* @return bool If the passport number is valid or not.
$preg = "/^[a-z]{2}[0-9]{7}$/";
// {{{ public function drive
* Validates an Irish driving licence
* This function will validate the number on an Irish driving licence.
* @param string $dl The drivers licence to validate
* @return bool true if it validates false if it doesn't.
$preg = "/^[0-9]{3}[0-9]{3}[0-9]{3}$/";
* Validate an Irish vehicle's license plate/registration number.
* @param string $number value to validate.
* @return bool true on success; else false.
//in_array is case sensitive, so use strtoupper...
$regex = "/^(\d{2,3})[\ -]([A-Z][A-Z]?)[\ -]\d{1,6}$/";
$marks = array ('C','CE','CN','CW','D','DL','G','KE','KK','KY','L',
'LD','LH','LK','LM','LS','MH','MN','MO','OY','RN',
'SO','TN','TS','W','WD','WH','WX','WW');
// The first component, if 3 digits in length can only end
if (strlen($matches[1 ]) == 3 ) {
$end = (int) substr($matches[1 ], 2 , 1 );
return ($end == 1 ) || ($end == 2 );
//two pre-1987 codes are still in use. ZZ and ZV.
//format is ZZ nnnnn - 5 digits for ZZ code and as few as 4 for ZV
$regex = "/^ZZ[\ -]\d{5}$/";
$regex = "/^ZV[\ -]\d{4,5}$/";
// {{{ public function sortCode
* Validate a sort code, no dashes or whitespace - just digits.
* @param string $sc The sort code.
// 6 digits expected - starting with a '9'.
return (preg_match('/^9[0-9]{5}$/', $sc)) ? true : false;
// {{{ public function bankAC
* Validate a bank account number
* This function will validate a bank account
* number for irish banks.
* @param string $ac The account number
* @param string $noSort Don't validate the sort codes, optional (default: false)
* @return bool true if the account validates
function bankAC($ac, $noSort = false )
$returnValue = preg_match($preg, $ac) ? true : false;
// {{{ public function ssn
* Ireland does not have a social security number system,
* the closest equivalent is a Personal Public Service Number.
* @param string $ssn ssn number to validate
* @link http://en.wikipedia.org/wiki/Personal_Public_Service_Number
* @see Validate_IE::ppsn()
* @return bool Returns true on success, false otherwise
// {{{ public function checkMOD23
* Return true if the checksum in the specified PPSN or vat number, without
* the 'IE' prefix, is valid.
* @param string $value Value to perform modulus 23 checksum on.
$total += (int) $value[$i]* (8- $i);
// {{{ public function ppsn
* Personal Public Service Number
* Ireland does not have a social security number system,
* the closest equivalent is a Personal Public Service Number.
* @param string $ppsn Personal Public Service Number
* @return bool Returns true on success, false otherwise
* @link http://en.wikipedia.org/wiki/Personal_Public_Service_Number
$preg = "/^[0-9]{7}[A-Z]$/";
$preg = "/^[0-9]{7}[A-Z][\ WTX]?$/";
// {{{ public function vatNumber
* Validate Irish VAT registration number.
* @param string $vat vat number to validate.
* require_once('Validate/IE.php');
* if ( Validate_IE::vatNumber($vat) ) {
* @return bool Returns true on success, false otherwise
* @link http://www.iecomputersystems.com/ordering/eu_vat_numbers.htm
* @link http://www.braemoor.co.uk/software/vat.shtml
// IE1234567X or IE1X34567X are valid (includes one or two letters
// either the last or second + last).
} elseif (preg_match('/^IE\d[a-z]\d{5}[a-z]$/i', $vat)) {
Documentation generated on Tue, 22 Jan 2013 14:30:02 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|