# Validation

{% hint style="success" %}
This is the official documentation of the `forestadmin/laravel-forestadmin` v2+ and `forestadmin/symfony-forestadmin` PHP agents.
{% endhint %}

![A field failing validation](https://647272774-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FABtuALf2WDQ7fxhI0JPa%2Fuploads%2Fgit-blob-8668bc8ffc7b3c737c80351447aa58c6eed2f303%2Ffield-validation-error.png?alt=media)

* Columns of type `VARCHAR(15)` will automatically carry a `less than 15 chars` validator.
* Non-nullable columns will automatically carry a `Present` validator.

However, you may want to enforce stricter restrictions than the ones which are implemented in your data source.

### Adding validation rules

The list of operators (`Present`, `LongerThan`, ...) which can be used when adding validators is the same as the [filter operators](https://docs.forestadmin.com/developer-guide-agents-php/data-sources/getting-started/queries/filters#operators).

```php
use ForestAdmin\AgentPHP\DatasourceCustomizer\CollectionCustomizer;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\ConditionTree\Operators;

$forestAgent->customizeCollection(
    'Customer',
    function (CollectionCustomizer $builder) {
        $builder->addFieldValidation('firstName', Operators::PRESENT])
        	->addFieldValidation('firstName', Operators::LONGER_THAN, 2)
            ->addFieldValidation('firstName', Operators::SHORTER_THAN, 13);
    }
);
```
