Cake\Localized\Validation\AuValidation::phone PHP Method

phone() public static method

Checks phone numbers for Australia.
public static phone ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function phone($check)
    {
        $normalized = preg_replace('/(\\s+|-|\\(|\\))/', '', preg_replace('/0011\\s?61/', '+61', $check));
        //remove spaces, parentheses and hyphens, convert full intl prefix.
        $pattern = '/^(((0|\\+61)[2378])(\\d){8}|((0|\\+61)[45](\\d){2}|1300|1800|190[02])(\\d){6}|(\\+61)?180(\\d){4}|(\\+61)?13\\d{4}|(\\+61)?12[2-8](\\d){1,7}|(\\+61|0)14[12357](\\d){6})$/';
        return (bool) preg_match($pattern, $normalized);
    }

Usage Example

Example #1
0
 /**
  * Test the phone method of AuValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(AuValidation::phone('02 5551 5678'));
     // Standard areacode + PSTN service number.
     $this->assertTrue(AuValidation::phone('0011 61 2 5551 5678'));
     // Full international prefix + standard areacode + PSTN service number.
     $this->assertTrue(AuValidation::phone('+61 2 5551 5678'));
     // Breif international prefix + standard areacode + PSTN service number.
     $this->assertTrue(AuValidation::phone('1300 555 567'));
     // 1300 local call cost number
     $this->assertTrue(AuValidation::phone('0412 515 678'));
     // Standard mobile number.
     $this->assertTrue(AuValidation::phone('0412515678'));
     // Standard mobile number, no whitespace.
     $this->assertTrue(AuValidation::phone('+61 412 515 678'));
     // Breif international prefix + standard mobile number.
     $this->assertTrue(AuValidation::phone('13 12 51'));
     // 13 local call cost number
     $this->assertTrue(AuValidation::phone('1902 345 678'));
     // 190X premium rate number.
     $this->assertTrue(AuValidation::phone('(02) 5551 5678'));
     // Standard areacode + PSTN service number, w/ parentheses.
     $this->assertTrue(AuValidation::phone('0145 124 458'));
     // Standard satellite service number.
     $this->assertTrue(AuValidation::phone('1800 123 456'));
     // 1800 Freecall number.
     $this->assertTrue(AuValidation::phone('180 1234'));
     // 180 Freecall number.
     $this->assertTrue(AuValidation::phone('+61 4 12 515 678'));
     // Breif international prefix + standard mobile number (unusually spaced).
     $this->assertTrue(AuValidation::phone('12456'));
     // Telstra utility service numbers. (directory service etc).
     $this->assertTrue(AuValidation::phone('127 22123'));
     // Testing numbers
     $this->assertFalse(AuValidation::phone('1300 TSTCAS'));
     // 1300 local call cost number (alphabetic representation).
     $this->assertFalse(AuValidation::phone('0198 333 888'));
     // prefix reserved for dial-up internet services.
 }