> For the complete documentation index, see [llms.txt](https://tcg.gitbook.io/voyager-2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tcg.gitbook.io/voyager-2/bread/validation.md).

# Validation

Voyager allows you to dynamically add validation rules to all formfields in a view.\
To start open the options for a formfield and look for the `Validation` section.\
Click the `+` button to add a rule and fill in the `Rule` and the `Message` which will be displayed when this rule fails. The message field is translatable to display translated error messages to users.

![Validation input](https://github.com/voyager-admin/voyager/blob/2.x/bread-builder/validation.png)

Please check the [Laravel documentation](https://laravel.com/docs/validation#available-validation-rules) for all available validation rules.

## Validating multi language inputs

You can validate the current app locale **or** all locales by setting the option to `Validate all locales` or `Validate current locale` in the layout options.\
With this you can use `Voyager::setLocales([...])` to dynamically set languages for various users.\
For example user A speaks english and german, you could run

```php
Voyager::setLocales(['de', 'en']);
```

in your service provider and select `Validate all locales` to force the user to enter the data in both his languages.

When `Validate current locale` is selected, only the current locale is validated. Other entered languages are **ignored**.

## Validating array elements

### Validating 1-dimensional arrays

Given then following array:

```php
[
    'name'  => 'admin',
    'email' => 'foo@bar.baz',
]
```

you can validate any fields by using `.name:required` or `.email:email` respectively.\
Please notice the leading `.` which tells Voyager that you want to validate a 1-dimensional array

### Multi-dimensional array

Given the following array of users:

```php
[
    [
        'name'  => 'Admin',
        'email' => 'foo@bar.baz',
    ],
    [
        'name'  => 'User',
        'email' => 'e@ma.il',
    ],
]
```

You can validate any fields in **all** elements (users in this case) by using `*.name:required` and `*.email:email`.\
Please notice the leading `*.` which tells Voyager that you want to validate a multi-dimensional array


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tcg.gitbook.io/voyager-2/bread/validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
