Skip to content

Instantly share code, notes, and snippets.

@valericus
Created January 22, 2016 01:21
Show Gist options
  • Save valericus/3144a428496b1bd89e1a to your computer and use it in GitHub Desktop.
Save valericus/3144a428496b1bd89e1a to your computer and use it in GitHub Desktop.
Валидация имени пользователя
from re import match, I
def login_is_valid_re(login: str):
return bool(
match('^[a-z][a-z0-9\-\.]{0,19}', login, I) and \
match('[a-z0-9\-\.]{0,19}[a-z0-9]$', login, I)
)
def login_is_valid(login: str):
head = 'abcdefghijklmnopqrstuvwxyz'
tail = head + '0123456789'
body = tail + '.-'
_login = login.lower()
return bool(
1 <= len(login) <= 20 and
_login[0] in head and
_login[-1] in tail and
[i for i in _login[1:-1] if i in body]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment