Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add uppercase validation rule #44918

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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