# `Arc.Validation`
[🔗](https://github.com/Cratis/Arc.Elixir/blob/main/lib/arc/validation.ex#L4)

Builds validation results and evaluates declarative field rules.

Field rules come from `field/3` options in a `schema` block (`required`, `min_length`,
`max_length`, `email`, `matches`, `min`, `max`, `greater_than`, `less_than`). The same rules
are written into the generated TypeScript validators, so the browser rejects what the server
would reject.

A command can add cross-field rules by defining `validate/2`, returning `:ok` or
`{:error, results}` built with `error/2`.

# `error`

```elixir
@spec error(String.t(), [atom() | String.t()], keyword()) :: Arc.ValidationResult.t()
```

Builds an error result for the given members.

    Arc.Validation.error("Already registered", [:name])

# `rules`

```elixir
@spec rules(keyword()) :: [map()]
```

The client-visible rule descriptors for a field's options, as `%{name: "minLength", args: [3]}`.

# `validate_fields`

```elixir
@spec validate_fields(struct(), [Arc.Schema.Field.t()]) :: [Arc.ValidationResult.t()]
```

Evaluates the declarative rules of every field in `fields` against `struct`.

# `warning`

```elixir
@spec warning(String.t(), [atom() | String.t()], keyword()) ::
  Arc.ValidationResult.t()
```

Builds a warning result.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
