diff --git a/src/PersianValidation.php b/src/PersianValidation.php index c37acb4..645e274 100644 --- a/src/PersianValidation.php +++ b/src/PersianValidation.php @@ -320,4 +320,20 @@ public function Less($attribute, $value, $parameters) } + /** + * iran phone number + * @param $attribute $value + * @author Shahrokh Niakan + * @since Agu 24, 2016 + * @return boolean + */ + public function IranPhone($attribute, $value) + { + + $this->status = preg_match('/^((0)([1-9]{2})([0-9]{8}))+$/', $value) ; + + return ( $this->status ? true : false ); + + } + } diff --git a/src/PersianValidationServiceProvider.php b/src/PersianValidationServiceProvider.php index 3b3b614..8b00253 100644 --- a/src/PersianValidationServiceProvider.php +++ b/src/PersianValidationServiceProvider.php @@ -193,6 +193,18 @@ public function boot() }); + // create custom rule for domain + Validator::extend('iran_phone', 'PersianValidation@IranPhone'); + + // create custom message for unsigned_num + Validator::replacer('iran_phone', function ($message, $attribute) { + + $this->new_message = "The $attribute must be a iran phone number."; + + return str_replace($message, $this->new_message, $message); + + }); + } /** diff --git a/tests/PersianValidationTest.php b/tests/PersianValidationTest.php index d0d8b59..ef1b8a0 100644 --- a/tests/PersianValidationTest.php +++ b/tests/PersianValidationTest.php @@ -415,4 +415,27 @@ public function testLess() $this->assertEquals(false, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters)); } + + /** + * iran phone number + * @author Shahrokh Niakan + * @since Agu 24, 2016 + * @return void + */ + public function testIranPhone() + { + + $this->value = '08337236555'; + + $this->assertEquals(true, $this->PersianValidation->IranPhone($this->attribute, $this->value)); + + $this->value = '21372365544'; + + $this->assertEquals(false, $this->PersianValidation->IranPhone($this->attribute, $this->value)); + + $this->value = '021372365541'; + + $this->assertEquals(false, $this->PersianValidation->IranPhone($this->attribute, $this->value)); + + } }