Skip to content

Commit

Permalink
Merge pull request #1814 from nowackipawel/patch-49
Browse files Browse the repository at this point in the history
extended exact_length[1,3,5]
  • Loading branch information
lonnieezell authored Mar 12, 2019
2 parents 9af0a89 + 192155a commit b2fda54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function differs(string $str = null, string $field, array $data): bool

/**
* Returns true if $str is $val characters long.
* $val = "5" (one) | "5,8,12" (multiple values)
*
* @param string $str
* @param string $val
Expand All @@ -74,6 +75,18 @@ public function differs(string $str = null, string $field, array $data): bool
*/
public function exact_length(string $str = null, string $val, array $data): bool
{
if(strpos($val, ',') !== 1)
{
$val = explode(',', $val);
foreach ($val as $tmp)
{
if(is_numeric($tmp) && (int) $tmp === mb_strlen($str))
{
return true;
}
}
}

return ((int) $val === mb_strlen($str));
}

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ alpha_numeric No Fails if field contains anything other than
alpha_numeric_space No Fails if field contains anything other than alpha-numeric characters, numbers or space.
decimal No Fails if field contains anything other than a decimal number.
differs Yes Fails if field does not differ from the one in the parameter. differs[field_name]
exact_length Yes Fails if field is not exactly the parameter value. exact_length[5]
exact_length Yes Fails if field is not exactly the parameter value. One or more comma-separated values. exact_length[5] or exact_length[5,8,12]
greater_than Yes Fails if field is less than or equal to the parameter value or not numeric. greater_than[8]
greater_than_equal_to Yes Fails if field is less than the parameter value, or not numeric. greater_than_equal_to[5]
in_list Yes Fails if field is not within a predetermined list. in_list[red,blue,green]
Expand Down

0 comments on commit b2fda54

Please sign in to comment.