Flarum 安装目录 extend.php
文件。这里实例的正则表达式只能匹配 example@xxx.edu.cn 的邮箱,如果想要匹配 example.teacher@xxx.edu.cn 这种昵称带有多个句号分隔的,使用这个正则 /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@xxx.edu.cn$/
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
use Flarum\Foundation\ValidationException;
use Flarum\User\Event\Saving;
use Illuminate\Support\Arr;
return [
// Register extenders here to customize your forum!
(new Extend\Event())
->listen(Saving::class, function (Saving $event) {
$email= Arr::get($event->data, 'attributes.email');
if (preg_match("/^[a-zA-Z0-9_-]+@xxx.edu.cn$/", $email) != 1) {
throw new ValidationException(["请使用校园邮箱"]);
}
}),
];