blessing-skin-server/app/Rules/PlayerName.php

37 lines
860 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class PlayerName implements Rule
{
public function passes($attribute, $value)
{
$regexp = '/.*/';
switch (option('player_name_rule')) {
case 'official':
// Mojang's official username rule
2019-12-22 14:25:22 +08:00
$regexp = '/^[A-Za-z0-9_]+$/';
break;
case 'cjk':
// CJK Unified Ideographs
$regexp = '/^[A-Za-z0-9_§\x{4e00}-\x{9fff}]+$/u';
break;
case 'custom':
$regexp = option('custom_player_name_regexp') ?: $regexp;
break;
}
2019-12-22 14:25:22 +08:00
return (bool) preg_match($regexp, $value);
}
public function message()
{
return trans('user.player.player-name-rule.'.option('player_name_rule'));
}
}