I'm trying to create a custom validation rule as folows:
$validator
->add('slug', 'custom', [
'rule' => function($value, $context) {
return preg_match('/^[a-z0-9\-]+$/', $value);
},
'message' => 'Slug cannot contain spaces or special characters'
]);
The rule works fine, but the message on form is always: "The provided value is invalid"
.