Validating text input

by  |  25-Nov-2019 19:46

validating text input-45validating text input-30validating text input-67

attribute works with the following input types: text, search, url, tel, email, and password.

Tip: Use the global title attribute to describe the pattern to help the user.

So our general format is going to look like this: food = ['pizza', 'burgers', 'sushi'] while True: answer = input('Would you like to get pizza, burgers, or sushi?

') if answer.lower() in food: break print("I don't know of a restaurant near here.".format(answer)) print("Okay, let's have .".format(answer)) Would you like to get pizza, burgers, or sushi? The isdigit method of a string makes sure that all of the character in the string are digits.

Our if statement is starting to get rather complicated. We do this with a try/except block, like this: If you are not familiar with try/except, it is used to catch errors.

Community Discussion