You need to define the regex by adding / at the begging and the end.
'code' => ['required', 'string', 'distinct', 'regex:/^#([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})#$/'],
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
As the title said, I have this rule
'stock.colorEntries.*.color.hexCode' => ['required', 'string', 'distinct',
'regex:#^([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$#']
I get this error :
ErrorException: preg_match(): No ending delimiter '#' found in file
My validations rules are already in array format, no pipes at all, even this error still occurs
The weird thing is when I assign the same rule to a non wrapped attribute in my request form, this error doesn't occurs. Maybe it's a bug when using regex for nested attributes
Please or to participate in this conversation.