Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

pinkary-project/pinkary.com

1505 stars
2 code files
View pinkary-project/pinkary.com on GitHub

app/Rules/NoBlankCharacters.php

Open in GitHub
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
 
final readonly class NoBlankCharacters implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$value = type($value)->asString();
 
if (preg_match("/\p{Cf}/u", $value)) {
$fail('The :attribute field cannot contain blank characters.');
}
}
}

app/Http/Requests/UserUpdateRequest.php

Open in GitHub
use App\Rules\NoBlankCharacters;
use Illuminate\Foundation\Http\FormRequest;
 
final class UserUpdateRequest extends FormRequest
{
public function rules(): array
{
$user = type($this->user())->as(User::class);
 
return [
'name' => ['required', 'string', 'max:255', new NoBlankCharacters],
// ...
];
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.