Skip to content

Commit 008a4dd

Browse files
Adds uppercase validation rule (#44918)
1 parent 5f134c7 commit 008a4dd

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,19 @@ public function validateLowercase($attribute, $value, $parameters)
11711171
return Str::lower($value) === $value;
11721172
}
11731173

1174+
/**
1175+
* Validate that an attribute is uppercase.
1176+
*
1177+
* @param string $attribute
1178+
* @param mixed $value
1179+
* @param array<int, int|string> $parameters
1180+
* @return bool
1181+
*/
1182+
public function validateUppercase($attribute, $value, $parameters)
1183+
{
1184+
return Str::upper($value) === $value;
1185+
}
1186+
11741187
/**
11751188
* Validate the MIME type of a file is an image MIME type.
11761189
*

tests/Validation/ValidationValidatorTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,33 @@ public function testLowercase()
18301830
], $v->messages()->keys());
18311831
}
18321832

1833+
public function testUppercase()
1834+
{
1835+
$trans = $this->getIlluminateArrayTranslator();
1836+
$v = new Validator($trans, [
1837+
'lower' => 'lowercase',
1838+
'mixed' => 'MixedCase',
1839+
'upper' => 'UPPERCASE',
1840+
'lower_multibyte' => 'carácter multibyte',
1841+
'mixed_multibyte' => 'carÁcter multibyte',
1842+
'upper_multibyte' => 'CARÁCTER MULTIBYTE',
1843+
], [
1844+
'lower' => 'uppercase',
1845+
'mixed' => 'uppercase',
1846+
'upper' => 'uppercase',
1847+
'lower_multibyte' => 'uppercase',
1848+
'mixed_multibyte' => 'uppercase',
1849+
'upper_multibyte' => 'uppercase',
1850+
]);
1851+
1852+
$this->assertSame([
1853+
'lower',
1854+
'mixed',
1855+
'lower_multibyte',
1856+
'mixed_multibyte',
1857+
], $v->messages()->keys());
1858+
}
1859+
18331860
public function testLessThan()
18341861
{
18351862
$trans = $this->getIlluminateArrayTranslator();

0 commit comments

Comments
 (0)