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

phone() public static method

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

Usage Example

Beispiel #1
0
 /**
  * test the phone method of NlValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(NlValidation::phone('020-5045100'));
     $this->assertTrue(NlValidation::phone('0572-212121'));
     $this->assertTrue(NlValidation::phone('0205045100'));
     $this->assertTrue(NlValidation::phone('0572212121'));
     $this->assertTrue(NlValidation::phone('0653123456'));
     $this->assertTrue(NlValidation::phone('06-53123456'));
     $this->assertFalse(NlValidation::phone('020-50451009'));
 }