17 lines
636 B
Python
17 lines
636 B
Python
import string
|
|
|
|
from django.contrib.auth.models import User
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from users.models import Player
|
|
|
|
def usernameValidator(username):
|
|
if User.objects.filter(username__iexact=username).first() is not None:
|
|
raise ValidationError("Sorry, this username is already in use")
|
|
|
|
if 3 < len(username) < 17:
|
|
raise ValidationError("Username must be between 3-16 characters long")
|
|
|
|
charset = set(string.ascii_letters + string.digits + "_-")
|
|
if not all(x in charset for x in username):
|
|
raise ValidationError("Username may only contain normal letters, numbers and _-") |