Validate a string containing any international alpha character.
InternationalString.php should be placed in App\Rules -> App\Rules\InternationalString.php
Example shows usage with validate method from the Request instance in a Controllers store method handling a POST request.
public function store(Request $request)
{
$request->validate([
'label' => ['required', new InternationalString()],
]);
$request->validated();
$model = new MyModel();
$model->fill($request->all());
$model->saveOrFail();
return $model;
}You can extend the valiation with custom characters, here spaces are included:
'name' => [new InternationalString('\s')]Validation allowing dashes and numerics, settings second parameter to true allows numerical values:
'title' => [new InternationalString('\-',true)]Validate with custom string message:
'name' => [new InternationalString('\s',false,'Please enter a valid full name')]Validate with custom translation key:
'name' => [new InternationalString('\s',false,'user.fullname')]