So I have this code:
def validate_username(username):
find_username = cursor.execute("SELECT username FROM user WHERE username = ?", (username, ))
if find_username.fetchone() is not None:
username_is_valid = False
invalid_reason = 'Username already exists'
elif len(username) > 255:
username_is_valid = False
invalid_reason = 'Invalid format'
elif not match(r"[^@]+@[^@]+\.[^@]+", username):
username_is_valid = False
invalid_reason = 'Username must be an email address'
else:
username_is_valid = True
invalid_reason = None
return username_is_valid, invalid_reason
So obviously, it will return one of those:
(False, 'Username already exists')
(False, 'Invalid format')
(False, 'Username must be an email address')
(True, None)
Now what I want to do is to pass those two arguments into variables so that they can be reused, printed, etc. but for some reason I can't really find how to do it online; I'm assuming because I don't word my question properly. Maybe someone here can provide some guidance?
Basically the goal here is to run the function with the username, then if the username is invalid, print why it's invalid and if it's valid, then proceed further.