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

phone() public static method

Checks a phone number for Norway.
public static phone ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function phone($check)
    {
        return (bool) preg_match('/^((\\d{8})|(\\d{3} \\d{2} \\d{3})|(\\d{2} \\d{2} \\d{2} \\d{2}))$/', $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the phone method of NoValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(NoValidation::phone('12345678'));
     $this->assertTrue(NoValidation::phone('12 34 56 78'));
     $this->assertTrue(NoValidation::phone('123 45 678'));
     $this->assertFalse(NoValidation::phone('1234567'));
     $this->assertFalse(NoValidation::phone('1234567489'));
 }