2021-10-07 19:15:53 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
from exception.invalidArgumentException import InvalidArgumentException
|
|
|
|
|
|
|
|
|
|
|
|
class GroupNameValidator:
|
2021-10-08 17:35:03 +02:00
|
|
|
MAX_GROUP_NAME_LENGTH: int = 20
|
2021-10-07 19:15:53 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def validate(group: str) -> None:
|
|
|
|
group = group.lower()
|
|
|
|
|
2021-10-08 17:35:03 +02:00
|
|
|
if len(group) > 0 and not re.match('^\w+$', group):
|
|
|
|
raise InvalidArgumentException(re.escape('Special characters are not allowed.'))
|
2021-10-07 19:15:53 +02:00
|
|
|
|
2021-10-08 17:35:03 +02:00
|
|
|
if len(group) > GroupNameValidator.MAX_GROUP_NAME_LENGTH:
|
|
|
|
raise InvalidArgumentException(re.escape(f'Group name length can not be greater than {GroupNameValidator.MAX_GROUP_NAME_LENGTH}.'))
|