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

phone() public static method

Checks a phone number for Taiwan.
public static phone ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function phone($check)
    {
        $pattern = '/^\\(?(0|\\+886)[-. ]?[2-9][\\)-. ]?([0-9][\\)-. ]?){2}([0-9][-. ]?){3}[0-9]{2}[0-9]?$/';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the phone method of TwValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(TwValidation::phone('+886277388066'));
     $this->assertTrue(TwValidation::phone('02-7738-8066'));
     $this->assertTrue(TwValidation::phone('02 7738 8066'));
     $this->assertTrue(TwValidation::phone('(02)7738-8066'));
     $this->assertTrue(TwValidation::phone('049-289-5371'));
     $this->assertTrue(TwValidation::phone('+886.49.289-5371'));
     $this->assertTrue(TwValidation::phone('+886-826-66056'));
     $this->assertTrue(TwValidation::phone('0800-080090'));
     $this->assertTrue(TwValidation::phone('0936-000-777'));
     $this->assertTrue(TwValidation::phone('0968-080785'));
 }