定制 webmintydotcom/laravel-person-name 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webmintydotcom/laravel-person-name

Composer 安装命令:

composer require webmintydotcom/laravel-person-name

包简介

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

README 文档

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

统计信息

  • 总下载量: 143
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固