<?php12namespace Pterodactyl\Rules;34use Illuminate\Contracts\Validation\Rule;56class Username implements Rule7{8/**9* Regex to use when validating usernames.10*/11public const VALIDATION_REGEX = '/^[a-z0-9]([\w\.-]+)[a-z0-9]$/';1213/**14* Validate that a username contains only the allowed characters and starts/ends15* with alphanumeric characters.16*17* Allowed characters: a-z0-9_-.18*19* @param string $attribute20*/21public function passes($attribute, $value): bool22{23return preg_match(self::VALIDATION_REGEX, mb_strtolower($value));24}2526/**27* Return a validation message for use when this rule fails.28*/29public function message(): string30{31return 'The :attribute must start and end with alpha-numeric characters and32contain only letters, numbers, dashes, underscores, and periods.';33}3435/**36* Convert the rule to a validation string. This is necessary to avoid37* issues with Eloquence which tries to use this rule as a string.38*/39public function __toString(): string40{41return 'p_username';42}43}444546