Source for file AU.php
Documentation is available at AU.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Specific validation methods for data used in Australia
* 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 Daniel O'Connor <daniel.oconnor@gmail.com>
* @author Tho Nguyen <tho.nguyen@itexperts.com.au>
* @author Alex Hayes <ahayes@wcg.net.au>
* @author Byron Adams <byron.adams54@gmail.com>
* @copyright 1997-2005 Daniel O'Connor
* @copyright 2006 Alex Hayes
* @copyright 2006 Byron Adams
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: AU.php,v 1.18 2008/10/26 17:53:50 clockwerx Exp $
* @link http://pear.php.net/package/Validate_AU
* Data validation class for Australia
* Contains code from Validate_AT, Validate_UK and Validate_NZ
* This class provides methods to validate:
* - Australian Business Number
* - Australian Company Number
* - Australian Regional codes
* @author Daniel O'Connor <daniel.oconnor@gmail.com>
* @author Tho Nguyen <tho.nguyen@itexperts.com.au>
* @author Alex Hayes <ahayes@wcg.net.au>
* @author Byron Adams <byron.adams54@gmail.com>
* @copyright 1997-2005 Daniel O'Connor
* @copyright 2006 Alex Hayes
* @copyright 2006 Byron Adams
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/Validate_AU
* Validate Austrialian postal codes.
* @param string $postcode postcode to validate
* @param bool $strong optional; strong checks against a list of postcodes
* @param string $dataDir optional; name of directory datafile is located in
* @static string $postcodes
* @return bool true if postcode is ok, false otherwise
function postalCode($postcode, $strong = false , $dataDir = null )
if (!isset ($postcodes)) {
if ($dataDir != null && (is_file($dataDir . '/AU_postcodes.txt'))) {
$file = $dataDir . '/AU_postcodes.txt';
$file = '@DATADIR@/Validate_AU/data/AU_postcodes.txt';
return in_array((string) $postcode, $postcodes, true );
* Validates Australian Regional Codes
* @param string $region regional code to validate
* @return bool Returns true on success, false otherwise
static $regions = array ("ACT", "NSW", "NT", "QLD", "SA", "TAS", "VIC", "WA");
return in_array (strtoupper ($region), $regions);
* Validate a telephone number.
* Note that this function supports the following notations:
* - Landline: 03 9999 9999
* - Mobile: 0400 000 000 (as above, but usually notated differently)
* - Indial: 131 812 / 1300 000 000 / 1800 000 000 / 1900 000 000
* - International: +61.3 9999 9999
* For International numbers, only +61 will be valid, as this is
* Australia's dial code, and the format MUST be +61.3, where 3 represents
* the state dial code, in this case, Victoria.
* Note: If the VALIDATE_AU_PHONENUMBER_STRICT flag is not supplied, then
* all spaces, dashes and parenthesis are removed before validation. You
* will have to strip these yourself if your data storage does not allow
* @param string $number The telephone number
* @param mixed[] $options A list of options
* 'strict' => true - do not common characters
* 'national' => true - validate national numbers
* 'indial' => true - 13, 1300, 1800, 1900
* 'other' => true - uncommon phone validations
* like premium sms, data and personal numbers
* 'international => true - international numbers
* for Australia (eg. +61.3 9999 9999)
* @todo Check that $flags contains a valid flag.
function phoneNumber($number, $options = array ('strict' => false ,
if (empty ($options['strict'])) {
$number = str_replace(array ('(', ')', '-', ' '), '', $number);
if (!empty ($options['national'])) {
$preg[] = "(0[3478][0-9]{8})";
$preg[] = "(02[3-9][0-9]{7})";
if (!empty ($options['indial'])) {
$preg[] = '(13[0-9]{4})';
$preg[] = "(1[3|8|9]00[0-9]{6})";
if (!empty ($options['international'])) {
$preg[] = "(\+61\.[23478][0-9]{8})";
//Other numbers, like premium SMS
if (!empty ($options['other'])) {
$preg[] = "(19[0-9]{4,6})";
//Universial Personal Phones
$preg[] = "(0550[0-9]{6})"; //VOIP range (proposed)
$preg[] = "(059[0-9]{7})"; //Enum testing numbers
$preg[] = "(0500[0-9]{6})"; //"Find me anywhere"
// the caller pays the bill)
$preg[] = "(0198[0-3][0-9]{5})";
foreach ($preg as $pattern) {
if (preg_match("/^" . $pattern . "$/", $number)) {
* Validate an Australian Company Number (ACN)
* The ACN is a nine digit number with the last digit
* being a check digit calculated using a modified
* modulus 10 calculation.
* @param string $acn ACN number to validate
* @return bool Returns true on success, false otherwise
* @link http://www.asic.gov.au/asic/asic_infoco.nsf/byheadline/Australian+Company+Number+(ACN)+Check+Digit
$weights = array (8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 );
foreach ($digits as $key => $digit) {
$sum += $digit * $weights[$key];
$complement = 0 - $remainder;
$complement = 10 - $remainder;
return ($digits[8 ] == $complement);
* Social Security Number.
* Australia does not have a social security number system,
* the closest equivalent is a Tax File Number
* @param string $ssn ssn number to validate
* @see Validate_AU::tfn()
* @return bool Returns true on success, false otherwise
* Australia does not have a social security number system,
* the closest equivalent is a Tax File Number.
* @param string $tfn Tax File Number
* @return bool Returns true on success, false otherwise
* @link http://en.wikipedia.org/wiki/Tax_File_Number
$weights = array (1 , 4 , 3 , 7 , 5 , 8 , 6 , 9 , 10 );
$length = array ("8", "9");
* Australian Business Number (ABN).
* Validates an ABN using a modulus calculation
* @param string $abn ABN to validate
* @return bool true on success, otherwise false
* @link http://www.ato.gov.au/businesses/content.asp?doc=/content/13187.htm
$weights = array (10 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 , 19 );
* Validate number against decimal checksum (check digit)
* A check digit is a form of redundancy check used
* for error detection, the decimal equivalent of a
* binary checksum. It consists of a single digit
* computed from the other digits in the message.
* @param array $digits Digits to check
* @param int $modulus Modulus
* @param array $weights Array containing weighting
* @param array $length Length
* @return bool true on success, otherwise false
* @link http://en.wikipedia.org/wiki/Check_digit
function checkDigit($digits, $modulus, $weights, $length)
foreach ($digits as $key => $digit) {
$sum += $digit * $weights[$key];
return !($sum % $modulus);
Documentation generated on Tue, 30 Dec 2008 06:30:03 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|