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

phone() public static method

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

Usage Example

Beispiel #1
0
 /**
  * test the phone method of FrValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(FrValidation::phone('04 76 96 12 32'));
     $this->assertTrue(FrValidation::phone('07-76-96-12-32'));
     $this->assertTrue(FrValidation::phone('08.76.96.12.32'));
     $this->assertTrue(FrValidation::phone('0876961232'));
     $this->assertTrue(FrValidation::phone('09 76 96 12 32'));
     $this->assertFalse(FrValidation::phone('04 76 96 12 3'));
     $this->assertFalse(FrValidation::phone('04 76 96 12 33 '));
     $this->assertFalse(FrValidation::phone('047696123323'));
     $this->assertFalse(FrValidation::phone('07 43 90 33'));
 }