Skip to content

Commit

Permalink
Adds uppercase validation rule (#44918)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnabil230 authored Nov 14, 2022
1 parent 5f134c7 commit 008a4dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,19 @@ public function validateLowercase($attribute, $value, $parameters)
return Str::lower($value) === $value;
}

/**
* Validate that an attribute is uppercase.
*
* @param string $attribute
* @param mixed $value
* @param array<int, int|string> $parameters
* @return bool
*/
public function validateUppercase($attribute, $value, $parameters)
{
return Str::upper($value) === $value;
}

/**
* Validate the MIME type of a file is an image MIME type.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,33 @@ public function testLowercase()
], $v->messages()->keys());
}

public function testUppercase()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, [
'lower' => 'lowercase',
'mixed' => 'MixedCase',
'upper' => 'UPPERCASE',
'lower_multibyte' => 'carácter multibyte',
'mixed_multibyte' => 'carÁcter multibyte',
'upper_multibyte' => 'CARÁCTER MULTIBYTE',
], [
'lower' => 'uppercase',
'mixed' => 'uppercase',
'upper' => 'uppercase',
'lower_multibyte' => 'uppercase',
'mixed_multibyte' => 'uppercase',
'upper_multibyte' => 'uppercase',
]);

$this->assertSame([
'lower',
'mixed',
'lower_multibyte',
'mixed_multibyte',
], $v->messages()->keys());
}

public function testLessThan()
{
$trans = $this->getIlluminateArrayTranslator();
Expand Down

0 comments on commit 008a4dd

Please sign in to comment.