> For the complete documentation index, see [llms.txt](https://samypesse.gitbook.io/blini/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://samypesse.gitbook.io/blini/references/validations.md).

# Validations

```javascript
import { Validation } from 'Blini'
```

A Validation allows you to define a transformation or rejection that will be applied to data before flushing to the database.

Validations are simple function accepting a value in input and returning a new value or throwing an error. Validations can be async by returning a promise.

* [General validations](/blini/references/validations.md#general-validations)
  * [required](/blini/references/validations.md#required)
  * [default](/blini/references/validations.md#default)
* [String validations](/blini/references/validations.md#string-validations)
  * [minLength](/blini/references/validations.md#minlength)
  * [maxLength](/blini/references/validations.md#maxlength)
  * [regExp](/blini/references/validations.md#regexp)
  * [oneOf](/blini/references/validations.md#oneof)
* [Iterable validations](/blini/references/validations.md#iterable-validations)
  * [limitAt](/blini/references/validations.md#limitat)

## General validations

### `required`

`Validation.required(message: String)`

Enforce that the field is set, throw an error with `message` otherwise.

### `default`

`Validation.default(value: Mixed)`

Defaults the value of the field if non existant. It doesn't reject the valuation, only transform the data set.

## String Validations

### `minLength`

`Validation.minLength(min: Number, message: String)`

Enforce that the string value is at least `min` characters long.

### `maxLength`

`Validation.maxLength(max: Number, message: String)`

Enforce that the string value is less than `max` characters long.

### `regExp`

`Validation.regExp(re: RegExp, message: String)`

Enforce that the string value match a RegExp (`re`).

### `oneOf`

`Validation.oneOf(constants: Array, message: String)`

Enforce that the value is one of the constants.

## Iterable Validations

### `limitAt`

`Validation.limitAt(max: Number)`

Enforce that iterable doesn't have more than `max` element, it does not throw error, but normalize the value.
