-
app/Rules/Username.php
Open in GitHubuse Illuminate\Contracts\Validation\Rule; class Username implements Rule { public const VALIDATION_REGEX = '/^[a-z0-9]([\w\.-]+)[a-z0-9]$/'; public function passes($attribute, $value): bool { return preg_match(self::VALIDATION_REGEX, mb_strtolower($value)); } public function message(): string { return 'The :attribute must start and end with alpha-numeric characters and contain only letters, numbers, dashes, underscores, and periods.'; } public function __toString() { return 'p_username'; } }
-
app/Models/User.php
Open in GitHubuse Pterodactyl\Rules\Username; class User extends Model { // public static function getRules() { $rules = parent::getRules(); $rules['language'][] = new In(array_keys((new self())->getAvailableLanguages())); $rules['username'][] = new Username(); return $rules; } // }