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

Commit

Permalink
Merge pull request #8 from anetwork/develop
Browse files Browse the repository at this point in the history
Added new validation more and less
  • Loading branch information
shahrokhniakan authored Aug 24, 2016
2 parents a63321f + 72ef256 commit e625f77
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ You can access to validation rules by passing the rules key according blew follo
| alpha_space | Accept alphabet and space |
| a_url | Checked correct url |
| a_domain | Checked correct domain |
| more | Checked value be max and not equal too|
| less | Checked value be min and not equal too |




Expand Down Expand Up @@ -142,5 +145,9 @@ Validator::make( $request->all(), [

'domain' => 'a_domain' // Validate domain

'more' => 'more:10' // Validate value be more than parameter

'less' => 'less:10' // Validate value be less than parameter

]);
```
40 changes: 40 additions & 0 deletions src/PersianValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,44 @@ public function Domain($attribute, $value)

}

/**
* value must be more than parameters
* @param $attribute $value $parameters
* @author Shahrokh Niakan <[email protected]>
* @since Agu 24, 2016
* @return boolean
*/
public function More($attribute, $value, $parameters)
{

if ( isset( $parameters[0] ) ) {

return ( $value > $parameters[0] ? true : false );

}

return false;

}

/**
* value must be less than parameters
* @param $attribute $value $parameters
* @author Shahrokh Niakan <[email protected]>
* @since Agu 24, 2016
* @return boolean
*/
public function Less($attribute, $value, $parameters)
{

if ( isset( $parameters[0] ) ) {

return ( $value < $parameters[0] ? true : false );

}

return false;

}

}
24 changes: 24 additions & 0 deletions src/PersianValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ public function boot()

});

// create custom rule for domain
Validator::extend('more', 'PersianValidation@More');

// create custom message for unsigned_num
Validator::replacer('more', function ($message, $attribute) {

$this->new_message = "The $attribute must be more than parameter.";

return str_replace($message, $this->new_message, $message);

});

// create custom rule for domain
Validator::extend('less', 'PersianValidation@Less');

// create custom message for unsigned_num
Validator::replacer('less', function ($message, $attribute) {

$this->new_message = "The $attribute must be less than parameter.";

return str_replace($message, $this->new_message, $message);

});

}

/**
Expand Down
50 changes: 50 additions & 0 deletions tests/PersianValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,54 @@ public function testDomain()
$this->assertEquals(false, $this->PersianValidation->Domain($this->attribute, $this->value));

}

/**
* unit test of more
* @author Shahrokh Niakan <[email protected]>
* @since Agu 24, 2016
* @return void
*/
public function testMore()
{

$this->value = 10;

$this->parameters[0] = 9;

$this->assertEquals(true, $this->PersianValidation->More($this->attribute, $this->value, $this->parameters));

$this->parameters[0] = 11;

$this->assertEquals(false, $this->PersianValidation->More($this->attribute, $this->value, $this->parameters));

$this->parameters[0] = 10;

$this->assertEquals(false, $this->PersianValidation->More($this->attribute, $this->value, $this->parameters));

}

/**
* unit test of less
* @author Shahrokh Niakan <[email protected]>
* @since Agu 24, 2016
* @return void
*/
public function testLess()
{

$this->value = 10;

$this->parameters[0] = 11;

$this->assertEquals(true, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters));

$this->parameters[0] = 9;

$this->assertEquals(false, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters));

$this->parameters[0] = 10;

$this->assertEquals(false, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters));

}
}

0 comments on commit e625f77

Please sign in to comment.