Add better message hints to RegEx validators

I realized that users wouldn't be able to understand why their username
was invalid, so rather than getting rid of it, I added message hints
and split it up into two different validators. If the first one fails,
the second one will show as well.

Not perfect, but better than before by a longshot.
This commit is contained in:
Xevion
2022-03-30 01:33:17 -05:00
parent 7da54f656d
commit d16df75bf5

View File

@@ -6,7 +6,10 @@ from validators import NoProfanity
class RegistrationForm(FlaskForm):
username = StringField('Username', [validators.Length(min=4, max=25),
validators.Regexp(r' ^[a-zA-Z0-9]+([._]?[a-zA-Z0-9]+)*$'),
validators.Regexp(r'^[a-zA-Z0-9_\.]+$',
message='Only letters, numbers, underscore character and dots are allowed.'),
validators.Regexp(r'^[a-zA-Z0-9]+([._]?[a-zA-Z0-9]+)*$',
message='Dots and underscores cannot be at the start of the username, repeat or touch.'),
NoProfanity()])
name = StringField('Name', [validators.Length(min=2, max=35), NoProfanity()])
password = PasswordField('New Password', [