Hexadecimal Color Rule

Validate a Hexadecimal Color Code

113k Downloads / Month

Open Source MIT License

public Intervention\Validation\Rules\HexColor::__construct(?int $length = null)

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

Parameters

length (optional)

Optional length as integer to check only for shorthand (3 characters) or full hexadecimal (6 characters) form.

Example

use Intervention\Validation\Rules\HexColor;

$validator = Validator::make($request->all(), [
    'attribute-key' => new HexColor(3),
]);
Edit