@devmain Sounds like you want conditional validation then rather than regex validation.
Jan 2, 2023
7
Level 1
Validation regex with laravel
I need to validate the array name field only when the ID starts with the letter E. I've tried several ways, including with regex and it doesn't work. Specifically the name field is not validating, the rest is normal.
public function rules(): array
{
return [
'products' => 'present|required|array|min:1',
'products.*.id' => 'required',
'products.*.name' => 'required_if:products.*.id|regex:/^e/',
];
}
Please or to participate in this conversation.