> ## Documentation Index
> Fetch the complete documentation index at: https://forest-chore-open-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Field validation

Most data sources can import validation rules from their target.
For instance, if you are using the SQL data source:

* 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 implemented in your data source.

## Adding validation rules

The list of operators (`Present`, `LongerThan`, ...) available when adding validators is the same as the filter operators.

```javascript theme={null}
collection
  .addFieldValidation('firstName', 'Present')
  .addFieldValidation('firstName', 'LongerThan', 2)
  .addFieldValidation('firstName', 'ShorterThan', 13)
  .addFieldValidation('firstName', 'Match', /^[a-z]+$/i);
```

## Custom validators

If you need to implement custom validators or validation over multiple fields you may use [change hooks](/product/process/advanced-concepts/hooks/overview).

## Make a field optional

If the introspection marks a field as required, and you would like to make it optional, use the `setFieldNullable` function on your collection.

<Warning>
  Be wary that if your database system does not allow empty values on the specified field, updating that field on records with an empty value will result in an error.
</Warning>

```javascript theme={null}
collection.setFieldNullable('firstName');
```
