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

mobile() public static method

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

Usage Example

Beispiel #1
0
 /**
  * test the mobile method of IrValidation
  *
  * @return void
  */
 public function testMobile()
 {
     $this->assertTrue(IrValidation::mobile('989123334444'));
     $this->assertTrue(IrValidation::mobile('00989353334444'));
     $this->assertTrue(IrValidation::mobile('+989363334444'));
     $this->assertTrue(IrValidation::mobile('+98 9373334444'));
     $this->assertTrue(IrValidation::mobile('(+98) 9383334444'));
     $this->assertTrue(IrValidation::mobile('+98-9323334444'));
     $this->assertTrue(IrValidation::mobile('+989203334444'));
     $this->assertFalse(IrValidation::mobile('teststring'));
     $this->assertFalse(IrValidation::mobile('999123334444'));
     $this->assertFalse(IrValidation::mobile('+999353334444'));
     $this->assertFalse(IrValidation::mobile('00999363334444'));
     $this->assertFalse(IrValidation::mobile('000989373334444'));
     $this->assertFalse(IrValidation::mobile('+00989383334444'));
     $this->assertFalse(IrValidation::mobile('+0989323334444'));
 }