Hexadecimal Color Rule

Validate a Hexadecimal Color Code

101k Downloads / Month

Open Source MIT License

public Intervention\Validation\Rules\HexColor::__construct(array $lengths = [3, 4, 6, 8])

The field under validation must be a valid hexadecimal color code.


lengths (optional)

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]),