Skip to content

Commit

Permalink
Add color validation docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Sep 27, 2024
1 parent df79893 commit 884f256
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/forms/docs/03-fields/17-color-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,26 @@ ColorPicker::make('rgb_color')
ColorPicker::make('rgba_color')
->rgba()
```

## Color picker validation

You may use Laravel's validation rules to validate the values of the color picker:

```php
use Filament\Forms\Components\ColorPicker;

ColorPicker::make('hex_color')
->regex('/^#([a-f0-9]{6}|[a-f0-9]{3})\b$/')

ColorPicker::make('hsl_color')
->hsl()
->regex('/^hsl\(\s*(\d+)\s*,\s*(\d*(?:\.\d+)?%)\s*,\s*(\d*(?:\.\d+)?%)\)$/')

ColorPicker::make('rgb_color')
->rgb()
->regex('/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/')

ColorPicker::make('rgba_color')
->rgba()
->regex('/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/')
```

0 comments on commit 884f256

Please sign in to comment.