Validates that a value is a valid CSS color.
CssColor(
?array $formats = null,
?string $message = null
);// by default, all possible ways to define a CSS color are considered valid
Validator::cssColor()->validate('#0f0f0f'); // true
Validator::cssColor()->validate('black'); // true
Validator::cssColor()->validate('rgb(0, 255, 0)'); // true
// ...
// restrict allowed formats
Validator::cssColor(formats: ['hex-long'])->validate('#0f0f0f'); // true
Validator::cssColor(formats: ['hex-long'])->validate('rgb(0, 255, 0)'); // false
Validator::cssColor(formats: ['hex-long', 'rgb'])->validate('rgb(0, 255, 0)'); // trueNote
An UnexpectedValueException will be thrown when a formats option is invalid.
type: ?array default: null
By default, all possible ways to define a CSS color are considered valid. Use this options to restrict the allowed CSS formats.
Available options are:
hex-longhex-long-with-alphahex-shorthex-short-with-alphabasic-named-colorsextended-named-colorssystem-colorskeywordsrgbrgbahslhsla
Examples: #0f0f0f, #0F0F0F
Examples: #0f0f0f50, #0F0F0F50
Examples: #0f0, #0F0
Examples: #0f05, #0F05
Colors names defined in the W3C list of basic names colors.
Examples: black, green
Colors names defined in the W3C list of extended names colors.
Examples: black, aqua, darkgoldenrod, green
Colors names defined in the CSS WG list of system colors.
Examples: AccentColor, VisitedText
Colors names defined in the CSS WG list of keywords.
Examples: transparent, currentColor
Examples: rgb(0, 255, 0), rgb(0,255,0)
Examples: rgba(0, 255, 0, 50), rgba(0,255,0,50)
Examples: hsl(0, 50%, 50%), hsl(0,50%,50%)
Examples: hsla(0, 50%, 50%, 0.5), hsla(0,50%,50%,0.5)
type: ?string default: The {{ name }} value is not a valid CSS color.
Message that will be shown if the input value is not a valid CSS color.
The following parameters are available:
| Parameter | Description |
|---|---|
{{ value }} |
The current invalid value |
{{ name }} |
Name of the invalid value |
{{ formats }} |
Selected formats |
1.2.0Created