Name Validation in Laravel
Alphabetic and Spaces
Names often contain spaces (e.g., first and last names). To allow alphabetic characters and spaces:
$request->validate([ 'name' => 'required|regex:/^[a-zA-Z\s]*$/', ]);
Including Dashes and Apostrophes
Some names might include dashes or apostrophes. You can adjust the regular expression to allow these:
$request->validate([ 'name' => 'required|regex:/^[a-zA-Z\s\'\-]*$/', ]);
Comments
Post a Comment