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

phone() public static method

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

Usage Example

Beispiel #1
0
 /**
  * test the phone method of LtValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(LtValidation::phone('+370 671 51221'));
     $this->assertTrue(LtValidation::phone('370 814 52222'));
     $this->assertTrue(LtValidation::phone('+370 (37) 85 85 96'));
     $this->assertTrue(LtValidation::phone('+370 69 44 44 96'));
     $this->assertTrue(LtValidation::phone('37052512288'));
     $this->assertTrue(LtValidation::phone('+37067151221'));
     $this->assertTrue(LtValidation::phone('+370-671-51221'));
     $this->assertTrue(LtValidation::phone('+370-881 51220'));
     $this->assertFalse(LtValidation::phone('+37069k62145'));
     $this->assertFalse(LtValidation::phone('+360 671 52222'));
     $this->assertFalse(LtValidation::phone('+370 8415 235555'));
     $this->assertFalse(LtValidation::phone('-37066666666'));
     $this->assertFalse(LtValidation::phone('+370 1 1523 44'));
     $this->assertFalse(LtValidation::phone('370 22 11 11 12 11'));
     $this->assertFalse(LtValidation::phone('+370 - 671-52222'));
     $this->assertFalse(LtValidation::phone('+370?671.52222'));
     $this->assertTrue(LtValidation::phone('8 (25) 25 21 22'));
     $this->assertTrue(LtValidation::phone('867252128'));
     $this->assertTrue(LtValidation::phone('8-716-76145'));
     $this->assertTrue(LtValidation::phone('8-(37)-74-66-99'));
     $this->assertFalse(LtValidation::phone('+8 25 25 25 14'));
     $this->assertFalse(LtValidation::phone('5 671 86523'));
     $this->assertFalse(LtValidation::phone('8-962-5555'));
     $this->assertFalse(LtValidation::phone('32155o55555'));
     $this->assertFalse(LtValidation::phone('5-625-86666'));
 }