Created
January 22, 2016 01:21
-
-
Save valericus/3144a428496b1bd89e1a to your computer and use it in GitHub Desktop.
Валидация имени пользователя
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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