From d16df75bf57a3eaed88c8e47c8fb7370a86b233f Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 30 Mar 2022 01:33:17 -0500 Subject: [PATCH] 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. --- forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/forms.py b/forms.py index aafe74e..8a5b0a5 100644 --- a/forms.py +++ b/forms.py @@ -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', [