I have an application in Python Flask, where a username field has a validation on length. I would also like to prevent spaces within the username. How could I achieve that?
class RegistrationForm(Form):
username = TextField('Username', [validators.Length(min=4, max=25)])
email = TextField('Email Address', [validators.Email(message='Invalid email address.')])
You should be able to ensure that using the Regexp validator. I use the regex Django uses for the username form:
This allows alphanumeric characters, dots, @, + and -. You can of course just use \w for alphanumeric characters.