PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Validate » Validate_AU » Manual

This package is in alpha state Package contains locale validation for Australia such as: Tax File Number Postal Code Phone Number Australian Business Number Australian Company Number Regions (States) See also : The API documentation The page on pear.php.net

Introduction

Introduction – introduction to Validate_AU

Description

The package offers some methods to validate specific data for Australia

Usage

General usage

Every module of Validate follows the same philosophy. Propose some validation method which returns a boolean result. Some methods have some optional parameters to set stronger checks.

sample

<?php

// Include the package
require_once 'Validate/AU.php';
?>

List of available validations

List of available validations – available validation in Validate_AU

Validate a Australian TFN / SSN

Most Australian's will have a TFN (Tax File Number) however not all, it is the closet equivalent we have to a Social Security Number. Note that this validation routine can be accessed through both Validate_AU::tfn() and Valdiate::ssn() methods.

sample

<?php

// Include the package
require_once('Validate/AU.php');

$badTFN = '23 456 782';
$result = Validate_AU::tfn($badTFN);
echo 'Test ' . $badTFN .' : <br />';
var_export($result);

echo '<br /><br />';
$goodTFN = '123 456 782';
$result = Validate_AU::tfn($goodTFN);
echo 'Test ' . $goodNationalId .' : <br />';
var_export($result);
?>

Output :

     
Test 23 456 782 :
false

Test 123 456 782 :
true
     
    

Validate a Australian postcode

Australian post code are 4 digit formed.

First parameter is the post code to validate.

An optional parameter for activate strong checks using a list of postcodes.

sample

<?php

// Include the package
require_once('Validate/AU.php');

$badPostCode = 'ABCD';
$result = Validate_AU::postalCode($badPostCode);
echo 'Test ' . $badPostCode .' : <br />';
var_export($result);

echo '<br /><br />';
$goodPostCode = '3000';
$result = Validate_AU::postalCode($goodPostCode);
echo 'Test ' . $goodPostCode .' : <br />';
var_export($result);
?>

Output :

     
Test ABCD :
false

Test 3000 :
true
     
    

sample using strong parameter

1234 appears to be a valid 4 digit postcode, however it does not appear in the official list.

<?php

// Include the package
require_once('Validate/AU.php');

$badPostCode = '1234';
$goodPostCode = '7930';

$result = Validate_AU::postalCode($badPostCode);
echo 'Test ' . $badPostCode .' : <br />';
var_export($result);

$result = Validate_AU::postalCode($badPostCode, false);
echo '<br /><br />Test ' . $badPostCode .' : <br />';
var_export($result);

$result = Validate_AU::postalCode($badPostCode, true);
echo '<br /><br />Test ' . $badPostCode .' : <br />';
var_export($result);

$result = Validate_AU::postalCode($goodPostCode, true);
echo '<br /><br />Test ' . $goodPostCode .' : <br />';
var_export($result);
?>

Output :

     
Test 1234 :
true

Test 1234 :
true

Test 1234 :
false

Test 7930 :
true
     
    

Validate an ABN

Validate an Australian Business Number.

sample

<?php

// Include the package
require_once('Validate/AU.php');

$badABN = '00 043 145 470';
$result = Validate_AU::abn($badABN);
echo 'Test ' . $badRegion .' : <br />';
var_export($result);

echo '<br /><br />';
$goodABN = '28 043 145 470';
$result = Validate_AU::abn($goodABN);
echo 'Test ' . $goodRegion .' : <br />';
var_export($result);
?>

Output :

     
Test 00 043 145 470 :
false

Test 28 043 145 470 :
true
     
    

Validate a Region / State

Validates a 2/3 region (state) code.

sample

<?php

// Include the package
require_once('Validate/AU.php');

$badRegion = 'asdf';
$result = Validate_AU::region($badVAT);
echo 'Test ' . $badRegion .' : <br />';
var_export($result);

echo '<br /><br />';
$goodRegion = 'VIC';
$result = Validate_AU::region($goodRegion);
echo 'Test ' . $goodRegion .' : <br />';
var_export($result);
?>

Output :

     
Test asdf :
false

Test VIC :
true
     
    

Validate a phonenumber

Validate an Australian phone number passed as first param. Second parameter can be used to specify flags that signify the type of number to be validated.

Flags can be any combination of the bitwise constants VALIDATE_AU_PHONENUMBER_* as follows:

Validate_AU Phone Number Flags
Flag Description
"VALIDATE_AU_PHONENUMBER_STRICT" If supplied then no spaces, parenthesis or dashes (-) will be removed.
"VALIDATE_AU_PHONENUMBER_NATIONAL" If supplied, then valid national numbers, both landline and mobile will pass validation.
"VALIDATE_AU_PHONENUMBER_INDIAL" If supplied, then valid indial (13/1300/1800/1900) numbers will pass validation.
"VALIDATE_AU_PHONENUMBER_INTERNATIONAL" If supplied, then valid international syntax will pass validation. EG. +61.3 9999 9999

sample

<?php

// Include the package
require_once('Validate/AU.php');

$nationalPhone       = '03 9999 9999';
$nationalStrictPhone = '0399999999';
$indialPhone         = '1300 131 121';
$internationalSyntax = '+61.3 8779 7212';

echo 'Test ' . $goodPhone .' : <br />';
$result = Validate_AU::phoneNumber($nationalPhone); // the flag VALIDATE_AU_PHONENUMBER_NATIONAL is default
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalPhone, VALIDATE_AU_PHONENUMBER_NATIONAL | VALIDATE_AU_PHONENUMBER_STRICT);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalPhone, VALIDATE_AU_PHONENUMBER_INDIAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalPhone, VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalPhone, VALIDATE_AU_PHONENUMBER_NATIONAL | VALIDATE_AU_PHONENUMBER_INDIAL | VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result);

echo '<br /><br />';
echo 'Test ' . $nationalStrictPhone .' : <br />';
$result = Validate_AU::phoneNumber($nationalStrictPhone);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalStrictPhone, VALIDATE_AU_PHONENUMBER_NATIONAL | VALIDATE_AU_PHONENUMBER_STRICT);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalStrictPhone, VALIDATE_AU_PHONENUMBER_INDIAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalStrictPhone, VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($nationalStrictPhone, VALIDATE_AU_PHONENUMBER_NATIONAL | VALIDATE_AU_PHONENUMBER_INDIAL | VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';

echo '<br /><br />';
echo 'Test ' . $indialPhone .' : <br />';
$result = Validate_AU::phoneNumber($indialPhone);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($indialPhone, VALIDATE_AU_PHONENUMBER_INDIAL | VALIDATE_AU_PHONENUMBER_STRICT);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($indialPhone, VALIDATE_AU_PHONENUMBER_INDIAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($indialPhone, VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($indialPhone, VALIDATE_AU_PHONENUMBER_NATIONAL | VALIDATE_AU_PHONENUMBER_INDIAL | VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';
echo '<br /><br />';

echo 'Test ' . $internationalSyntax .' : <br />';
$result = Validate_AU::phoneNumber($internationalSyntax);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($internationalSyntax, VALIDATE_AU_PHONENUMBER_INTERNATIONAL | VALIDATE_AU_PHONENUMBER_STRICT);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($internationalSyntax, VALIDATE_AU_PHONENUMBER_INDIAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($internationalSyntax, VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';
$result = Validate_AU::phoneNumber($internationalSyntax, VALIDATE_AU_PHONENUMBER_NATIONAL | VALIDATE_AU_PHONENUMBER_INDIAL | VALIDATE_AU_PHONENUMBER_INTERNATIONAL);
var_export($result) . '-';

?>

Output :

     
Test 03 9999 9999 :
true - false - false - false - true

Test 0399999999 :
true - true - false - false - true

Test 1300 131 121 :
false - false - true - false - true

Test +61.3 8779 7212 :
false - false - true - true - true
     
    

Package Validate_AU Constants

Package Validate_AU Constants – Constants defined in and used by Validate_AU

All Constants

Constants defined in Validate_AU.php

Name Value Line Number
VALIDATE_AU_PHONENUMBER_INDIAL 4 37
VALIDATE_AU_PHONENUMBER_INTERNATIONAL 8 38
VALIDATE_AU_PHONENUMBER_NATIONAL 2 36
VALIDATE_AU_PHONENUMBER_STRICT 1 35

Validate_AU::abn

Validate_AU::abn() – Australian Business Number (ABN).

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::abn ( string $abn )

Description

Validates an ABN using a modulus calculation

Parameter

string $abn

ABN to validate

Return value

returns Returns true on success, otherwise false

Throws

throws no exceptions thrown

author

author Byron Adams <byron.adams54@gmail.com>

See

see http://www.ato.gov.au/businesses/content.asp?doc=/content/13187.htm

Note

This function can not be called statically.

Validate_AU::acn

Validate_AU::acn() – Validate an Australian Company Number (ACN)

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::acn ( string $acn )

Description

The ACN is a nine digit number with the last digit being a check digit calculated using a modified modulus 10 calculation.

Parameter

string $acn

ACN number to validate

Return value

returns Returns true on success, false otherwise

Throws

throws no exceptions thrown

author

author Byron Adams <byron.adams54@gmail.com>

author Daniel O'Connor <daniel.oconnor@gmail.com>

See

see http://www.asic.gov.au/asic/asic_infoco.nsf/byheadline/Australian+Company+Number+(ACN)+Check+Digit

Note

This function can not be called statically.

Validate_AU::phoneNumber

Validate_AU::phoneNumber() – Validate a telephone number.

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::phoneNumber ( string $number , int $flags = VALIDATE_AU_PHONENUMBER_NATIONAL )

Description

Note that this function supports the following notations:

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 these characters.

Parameter

string $number

The telephone number

integer $flags

Can be a combination of the following flags:

  • VALIDATE_AU_PHONENUMBER_STRICT: if supplied then no spaces, parenthesis or dashes (-) will be removed.
  • VALIDATE_AU_PHONENUMBER_NATIONAL: when supplied valid national numbers (eg. 03 9999 9999) will return TRUE.
  • VALIDATE_AU_PHONENUMBER_INDIAL: when supplied valid indial numbers (eg. 13/1300/1800/1900) will return TRUE.
  • VALIDATE_AU_PHONENUMBER_INTERNATIONAL: when supplied valid international notation of Australian numbers (eg. +61.3 9999 9999) will return TRUE.

ToDo

todo Check that $flags contains a valid flag.

Throws

throws no exceptions thrown

author

author Alex Hayes <ahayes@wcg.net.au>

author Daniel O'Connor <daniel.oconnor@gmail.com>

Note

This function can not be called statically.

Validate_AU::postalCode

Validate_AU::postalCode() – Validate Austrialian postal codes.

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::postalCode ( string $postcode , bool $strong = false )

Description

This package is not documented yet.

Parameter

string $postcode

postcode to validate

boolean $strong

strong checks against a list of postcodes

Return value

returns true if postcode is ok, false otherwise

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Validate_AU::region

Validate_AU::region() – Validates Australian Regional Codes

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::region ( string $region )

Description

This package is not documented yet.

Parameter

string $region

region code to validate

Return value

returns returns true on success, false otherwise

Throws

throws no exceptions thrown

See

see http://www.google.com/apis/adwords/developer/adwords_api_regions.html#Australia

author

author Byron Adams <byron.adams54@gmail.com>

Note

This function can not be called statically.

Validate_AU::ssn

Validate_AU::ssn() – Social Security Number.

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::ssn ( string $ssn )

Description

Australia does not have a social security number system, the closest equivalent is a Tax File Number

Parameter

string $ssn

ssn number to validate

Return value

returns Returns true on success, false otherwise

Throws

throws no exceptions thrown

See

see Validate_AU::tfn()

Note

This function can not be called statically.

Validate_AU::tfn

Validate_AU::tfn() – Tax File Number (TFN)

Synopsis

require_once '/Validate/AU.php';

bool Validate_AU::tfn ( string $tfn )

Description

Australia does not have a social security number system, the closest equivalent is a Tax File Number.

Parameter

string $tfn

Tax File Number

Return value

returns Returns true on success, false otherwise

Throws

throws no exceptions thrown

author

author Byron Adams <byron.adams54@gmail.com>

See

see http://en.wikipedia.org/wiki/Tax_File_Number

Note

This function can not be called statically.