---
title: "Validation — Contacts for Laravel | Roundly"
description: "Reuse the package’s validation in your forms: the ValidContactValue rule, ContactType::rules() and ready rules for repeatable contact arrays."
url: https://roundly-consulting.com/open-source/docs/contacts-for-laravel/validation
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Contacts for Laravel](https://roundly-consulting.com/open-source/docs/contacts-for-laravel.md)

# Validation

ValidContactValue is a standalone, reusable ValidationRule — apply it to any field. It normalizes the value first, then validates it against the kind’s rules and the 255-character cap:

```php
use RoundlyConsulting\Contacts\Enums\ContactType;
use RoundlyConsulting\Contacts\Rules\ValidContactValue;

$request->validate([
    'email' => ['required', new ValidContactValue(ContactType::Email)],
]);
```

## One-line FormRequest rules

ContactType::rules() returns a ready rule array — the kind’s field rules (required, string, …) plus ValidContactValue, which checks the normalized value — so a FormRequest stays a one-liner and accepts exactly what addEmail(), addPhone() and addUrl() accept (' A.Person@Example.COM ', '+421 900 000 000', 'example.com'):

```php
public function rules(): array
{
    return [
        'email' => ContactType::Email->rules(),       // or ContactType::rulesFor(ContactType::Email)
        'phone' => ContactType::Phone->rules(),
    ];
}
```

For a registered custom kind use ContactRules::forValue(ContactType::Custom, 'whatsapp'). The validated input is still the raw string; the package normalizes it when you add it.

## Repeatable contact arrays

For a repeatable list of {type, value} pairs, generate contacts.\* rules: each type must be a built-in or registered kind, and each value is normalized and validated against the rules of the kind its entry declares:

```php
use RoundlyConsulting\Contacts\Facades\Contacts;
use RoundlyConsulting\Contacts\Support\ContactRules;

$request->validate(Contacts::validationRules());       // keys: contacts, contacts.*.type, contacts.*.value
$request->validate(ContactRules::forArray('people'));  // custom prefix

Contacts::validationRules();
// [
//     'contacts' => ['sometimes', 'array'],
//     'contacts.*.type' => ['required', 'string', 'in:email,phone,address,url,social,custom'],
//     'contacts.*.value' => ['required', 'string', new ValidContactEntryValue],
// ]

ContactRules::kinds();                                    // built-in kinds + every key in contacts.types
ContactRules::forValue(ContactType::Url);                 // same as ContactType::Url->rules()
ContactRules::forValue(ContactType::Custom, 'whatsapp');  // a registered custom kind's rules
```

The type rule accepts the six built-ins plus every registered custom kind. The value rule, ValidContactEntryValue, reads the sibling type of the same entry — contacts.3.value against contacts.3.type — and applies that kind’s rules, a custom kind’s registered ones included. An entry whose type is missing or unknown is left to the type rule, which reports it.

## Error messages

Failures use the contacts::errors.invalid\_value translation (“The given value is not a valid :type contact.”), naming the custom kind rather than custom where one applies. It ships in English and Slovak; publish contacts-translations to reword it or add another language.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/contacts-for-laravel.md)
