Search code examples
laravellaravel-validation

Space required laravel validation


I want to store a full_name , and this full name i want always to be like this 'example example' or 'name last_name , string always contain a space in the middle'

'full_name' => 'required|string|min:3|max:50',


Solution

  • Try this 'full_name' => 'regex:/(\w+\s).+/'

    Update:

    By the way, I would consider splitting it into two fields like first_name and last_name. In this case, you could concat them in the back-end and problem solved.

    Also, looking further into the future, there could be a situation where you want to pass first and the last name separately for 3rd parties and this is usually the case i.e. domain registration.