Hexadecimal Color Rule
Validate a Hexadecimal Color Code
117k Downloads / Month
Open Source MIT License
117k Downloads / Month
Open Source MIT License
Explore how to validate hexadecimal color codes also known as web colors with the additional validation rules of Intervention Validation for your Laravel application.
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]),
]);
Edit