webmintydotcom/laravel-person-name

A Laravel validation rule to validate a person's first and last name.

Maintainers

Package info

github.com/webmintydotcom/laravel-person-name

pkg:composer/webmintydotcom/laravel-person-name

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-04-09 22:57 UTC

This package is auto-updated.

Last update: 2026-04-09 23:00:42 UTC


README

A Laravel validation rule for validating a person's first and last name. Unicode-safe and supports names from any language or culture.

Installation

composer require webmintydotcom/laravel-person-name

The service provider is auto-discovered by Laravel.

Usage

Basic Usage

use Webminty\PersonName\Rules\ValidPersonName;

$request->validate([
    'first_name' => ['required', new ValidPersonName],
    'last_name' => ['required', new ValidPersonName],
]);

Custom Minimum Length

The default minimum length is 2 characters. You can change it:

$request->validate([
    'first_name' => ['required', new ValidPersonName(minLength: 1)],
    'last_name' => ['required', new ValidPersonName(minLength: 3)],
]);

In a Form Request

use Webminty\PersonName\Rules\ValidPersonName;

class StoreUserRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'first_name' => ['required', new ValidPersonName],
            'last_name' => ['required', new ValidPersonName],
        ];
    }
}

What It Validates

The rule checks that a name:

  • Is a string
  • Meets the minimum length (default: 2)
  • Starts and ends with a letter
  • Only contains letters, spaces, hyphens, apostrophes, and periods

Valid Names

Name Why
John Simple name
Smith-Jones Hyphenated
O'Brien Apostrophe
De La Cruz Spaces
St. John Period
Jose Accented characters
Munoz Tilde
Dmitriy Cyrillic
Muhammad Arabic
Taro CJK characters

Invalid Names

Input Why
A Too short (default min: 2)
John3 Contains numbers
John@Doe Special characters
John- Trailing hyphen
John' Trailing apostrophe
Only spaces

Error Messages

The package includes English translations out of the box:

  • The :attribute must be a string.
  • The :attribute must be at least :min characters.
  • The :attribute may only contain letters, spaces, hyphens, apostrophes, and periods.

Customizing Messages

Publish the translations to customize them:

php artisan vendor:publish --tag=person-name-translations

Or override them inline:

$request->validate(
    ['first_name' => ['required', new ValidPersonName]],
    ['first_name.Webminty\PersonName\Rules\ValidPersonName' => 'Please enter a valid first name.'],
);

Requirements

  • PHP 8.2+
  • Laravel 11, 12, or 13

License

MIT

Thank you

Webminty team