![]() |
equalto validator doesnt work - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: equalto validator doesnt work (/thread-42235.html) |
equalto validator doesnt work - robertkwild - May-31-2024 hi all, my code below doesnt work ie the new password and confirm new password, the user on the web when they click the submit button they dont get the message saying passwords dont match and i have no idea why the length validator works fine, ive imported the modules from wtforms.validators import InputRequired, Length, DataRequired, EqualTo, Regexp new_password = PasswordField('New_Password', validators=[InputRequired(), Length(min=12), EqualTo('confirm_new_password', message='Passwords must match')]) confirm_new_password = PasswordField('Confirm_New_Password')thanks, rob RE: equalto validator doesnt work - Pedroski55 - Jun-02-2024 If your validator is invalid: Do it yourself! import re # password must contain at least 3 CAPITAL LETTERS # password must contain at least 3 digits # password must contain at least 1 small letter def validator(): e = re.compile(r'\A(?=[^a-z]*[a-z])(?=(?:[^A-Z]*[A-Z]){3})(?=\D*\d{3}).*') print('Your password MUST contain at least 1 small letter.') print('Your password MUST contain at least 3 capital letters and at least 3 digits.') print('You password may contain spaces and any or all of these: @#$%^&* to make it safer.') pw1 = input('Please enter a password you can remember. ') while not e.match(pw1): print('Your password MUST contain at least 3 capital letters and at least 3 digits.') print('You password may contain spaces and any or all of these: @#$%^&* to make it safer.') pw1 = input('Please enter a password you can remember. ') pw2 = input('Please enter the password you just wrote again. ') while not pw1 == pw2: print('Looks like you have problems with simple instructions. Let\'s try that again!') pw1 = input('Please enter a password you can remember. ') while not e.match(pw1): print('Your password MUST contain at least 3 capital letters and at least 1 digit.') print('You password may contain any or all of these: @#$%^&* to make it safer.') pw1 = input('Please enter a password you can remember. ') print('Now, please try to write the EXACT SAME password again, thank you.') print('If you can not write the same password again, this loop will never end ... ') pw2 = input('Please enter the password you you just wrote again. ') return pw1 password = validator()Gives: Although, I would rather use PHP to do this on a register.html page!But I don't know how to use Python for webpages! |