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

phone() public static method

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

Usage Example

Example #1
0
 /**
  * test the phone method of EsValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(EsValidation::phone('924227227'));
     $this->assertTrue(EsValidation::phone('924.227.227'));
     $this->assertTrue(EsValidation::phone('924-227-227'));
     $this->assertTrue(EsValidation::phone('924-22-72-27'));
     $this->assertTrue(EsValidation::phone('924 22 72 27'));
     $this->assertTrue(EsValidation::phone('924227227'));
     $this->assertTrue(EsValidation::phone('624227227'));
     $this->assertTrue(EsValidation::phone('924-227227'));
     $this->assertTrue(EsValidation::phone('827-227227'));
     $this->assertTrue(EsValidation::phone('91-2227227'));
     $this->assertFalse(EsValidation::phone('127227227'));
     $this->assertFalse(EsValidation::phone('813 4567'));
 }