I\'m using django-allauth, and for some reason the username default allows:
\"letters, digits and @/./+/-/_.\"
How can I ensure usernames are strictly alphanumer
I think python's builtin function str.isalnum() could be usefull here.
class UsernameMaxAdapter(DefaultAccountAdapter):
def clean_username(self, username):
# assumes "username" is a type of "str" object
if not username.isalnum():
raise ValidationError("Use only alphanumeric characters")
# your logic
UPDATE-1
set ACCOUNT_USERNAME_VALIDATORS in settings.py as mentioned in documentation
class CustomValidator(object):
def __call__(self, username="", *args, **kwargs):
username = username.isalnum()
if not username:
raise ValidationError("Use only alphanumeric characters")
in your settings.py,
custom_username_validators = [CustomValidator()]
ACCOUNT_USERNAME_VALIDATORS = 'path.to.settings.custom_username_validators'