I\'m using django-allauth, and for some reason the username default allows:
\"letters, digits and @/./+/-/_.\"
How can I ensure usernames are strictly alphanumer
You could use a regex expression to ensure that a username contains only allowed characters. For alphanumeric characters the following should do the trick:
import re
def is_valid_username(username):
pattern = re.compile('([a-zA-Z]+|\d+)')
return ''.join(re.findall(pattern, username)) == username
Here's an example of the output:
username_list = ["WhatAGre4tUsern4me", "548ThatISAgoodUsername005",
"CheckOutMy_Username", "It'sAUsern@me"]
print([is_valid_username(u) for u in username_list])
>>> [True, True, False, False]