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

phone() public static method

Checks a phone number for Iran.
public static phone ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function phone($check)
    {
        $pattern = '/^[- .\\(\\)]?((98)|(\\+98)|(0098)|0){1}[- .\\(\\)]{0,3}[1-9]{1}[0-9]{1,}[- .\\(\\)]*[0-9]{3,8}[- .\\(\\)]?$/';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the phone method of IrValidation
  *
  * @return void
  */
 public function testPhone()
 {
     $this->assertTrue(IrValidation::phone('982133334444'));
     $this->assertTrue(IrValidation::phone('00982133334444'));
     $this->assertTrue(IrValidation::phone('+982133334444'));
     $this->assertTrue(IrValidation::phone('+98 2133334444'));
     $this->assertTrue(IrValidation::phone('+98 21 33334444'));
     $this->assertTrue(IrValidation::phone('+98-21-33334444'));
     $this->assertTrue(IrValidation::phone('(+98) (21) (33334444)'));
     $this->assertTrue(IrValidation::phone('02133334444'));
     $this->assertTrue(IrValidation::phone('021 33334444'));
     $this->assertTrue(IrValidation::phone('021 33334444'));
     $this->assertTrue(IrValidation::phone('(021) (118)'));
     $this->assertTrue(IrValidation::phone('0411 3334444'));
     $this->assertTrue(IrValidation::phone('(0411) (3334444)'));
     $this->assertFalse(IrValidation::phone('teststring'));
     $this->assertFalse(IrValidation::phone('992133334444'));
     $this->assertFalse(IrValidation::phone('+992133334444'));
     $this->assertFalse(IrValidation::phone('00992133334444'));
     $this->assertFalse(IrValidation::phone('000982133334444'));
     $this->assertFalse(IrValidation::phone('+00982133334444'));
     $this->assertFalse(IrValidation::phone('+0982133334444'));
     $this->assertFalse(IrValidation::phone('+98/21/33334444'));
     $this->assertFalse(IrValidation::phone('+02133334444'));
     $this->assertFalse(IrValidation::phone('021 22'));
 }