Im working on Laravel 4.2. Im trying to use Validator to validate a name field with regex, here is my rule below:
public static $rules_save = [
'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/'
preg_match(): No ending delimiter '/' found
Since your regex has a pipe in it, you have to use an array:
public static $rules_save = [ 'class_subjects' => ['required', 'regex:/[0-9]([0-9]|-(?!-))+/'], ];
From the docs:
When using the
regexpattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.