Make "HexRgbColor" rule case-insensitive

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2020-10-04 12:07:09 +02:00
parent 444f105ea6
commit 1809e9f4c4
No known key found for this signature in database
GPG key ID: 221E9281655813A6
3 changed files with 6 additions and 1 deletions

View file

@ -6,6 +6,7 @@ Validates weather the input is a hex RGB color or not.
```php
v::hexRgbColor()->validate('#FFFAAA'); // true
v::hexRgbColor()->validate('#ff6600'); // true
v::hexRgbColor()->validate('123123'); // true
v::hexRgbColor()->validate('FCD'); // true
```
@ -18,6 +19,7 @@ v::hexRgbColor()->validate('FCD'); // true
Version | Description
--------|-------------
2.1.0 | Allow hex RGB colors to be case-insensitive
2.0.0 | Allow hex RGB colors with 3 integers
0.7.0 | Created

View file

@ -23,6 +23,6 @@ final class HexRgbColor extends AbstractEnvelope
{
public function __construct()
{
parent::__construct(new Regex('/^#?([0-9A-F]{3}|[0-9A-F]{6})$/'));
parent::__construct(new Regex('/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i'));
}
}

View file

@ -37,11 +37,14 @@ final class HexRgbColorTest extends RuleTestCase
return [
[$sut, '#000'],
[$sut, '#00000F'],
[$sut, '#00000f'],
[$sut, '#123'],
[$sut, '#123456'],
[$sut, '#FFFFFF'],
[$sut, '#ffffff'],
[$sut, '123123'],
[$sut, 'FFFFFF'],
[$sut, 'ffffff'],
[$sut, 443],
];
}