Using Linguist it's possible to change the translation for the "regex" error message but the problem would be that it would apply anywhere a regex validation is used in Flarum, which isn't desirable.
The following works if there's a single regex:
rule on the UserValidator:
If a different extension were to register a regex rule on the user validation and define a custom error message as well, the last message registered would be used for both rules.
<?php
use Flarum\Extend;
use Flarum\User\UserValidator;
return [
// Register extenders here
(new Extend\Validator(UserValidator::class))
->configure(function ($flarumValidator, $validator) {
$rules = $validator->getRules();
if (!array_key_exists('email', $rules)) {
return;
}
$rules['email'][] = 'regex:/@example\.com$/';
$validator->setRules($rules);
$validator->setCustomMessages([
'email.regex' => 'The email address must use @example.com domain.',
]);
}),
];
If support for multiple regexes are required with each a custom message on the UserValidator, a custom validation callback could be used instead of the regex:
rule, so that it can provide a custom error message that doesn't apply to any other rule.