Hexadecimal Color Rule
Validate a Hexadecimal Color Code
172k Downloads / Month
Open Source MIT License
172k Downloads / Month
Open Source MIT License
Validate hexadecimal color codes (web colors) in Laravel with Intervention Validation. #RGB and #RRGGBB formats.
public Intervention\Validation\Rules\HexColor::__construct(array $lengths = [3, 4, 6, 8])
The field under validation must be a valid hexadecimal color code.
Pass optionally allowed lengths as an array to check only for shorthand (3 or 4 characters) or full hexadecimal (6 or 8 characters) form or combinations.
use Illuminate\Support\Facades\Validator; use Intervention\Validation\Rules\HexColor; $validator = Validator::make($request->all(), [ 'attribute-key' => new HexColor([3, 6]), ]);