Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
Added iran_phone validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahrokh Niakan committed Aug 24, 2016
1 parent c53b913 commit 731b6ea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/PersianValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,20 @@ public function Less($attribute, $value, $parameters)

}

/**
* iran phone number
* @param $attribute $value
* @author Shahrokh Niakan <[email protected]>
* @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 );

}

}
12 changes: 12 additions & 0 deletions src/PersianValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

});

}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/PersianValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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));

}
}

0 comments on commit 731b6ea

Please sign in to comment.