I wrote this validator:
no_space_validator = RegexValidator(
r'^[^\s]+$',
_('No spaces allowed'),
code='invalid_username')
and I have it set in the Form field:
username = CharField(
label='Username',
validators=[no_space_validator])
But still it allows me to submit usernames with spaces. I can't see how me regex is wrong here or how can I express no spaces in any other way.
You can do it like this (note the capital S):
Read the docs for more info: https://docs.djangoproject.com/en/dev/ref/validators/#regexvalidator
Here is more simple approach: