-1

If you ask a user to input a value, which will be a string, how do I validate it in such a way that only accepts their input once they have entered a specific character within their input.

Sorry if this is a duplicate question but I have looked through so many questions and answers but they were only for one specific character to be entered, meanwhile I am trying to make the user enter the @ sign into their email in order to validate it.

for example:

email_address = input("Please enter your email address:")
if email_address

else:
    break

I understand how to end the loop once they have entered the right character in their email, but I don't understand how I can get them to include the @ symbol in their response. Hopefully what I am saying makes sense, thank you for any help in advance.

1 Answers1

0

The canonical low-tech way is to set a flag that changes only when you get valid input.

bad_input = True
while bad_input:
    email_address = input("Please enter your email address:")
    if email_address:  # if the input is valid
        bad_input = False
    else:
        print "Bad input"    # Make a better message, please
Prune
  • 76,765
  • 14
  • 60
  • 81