django alphanumeric validator not work -
i try force user use alphanumeric characters in
field wrote following code in user model:
alphanumeric = regexvalidator(r'^[0-9a-za-z]*$', message='only alphanumeric characters allowed.') username = models.charfield(unique=true, max_length=20, validators=[alphanumeric])
but still can create:
user.objects.create(username="@@")
i don't want create it...
am doing wrong? did wrote wrong regex validator?
i think code should this:
username = models.charfield(unique=true, max_length=20, validators=[ regexvalidator( r'^[0-9a-za-z]*$', message='only alphanumericcharacters allowed.', code='invalid_username' ) ] )
Comments
Post a Comment