I'm writing a program that will take a string as an input and check if the elements in it are valid or not. I want my input to only contain lower characters and periods, exclamation marks, and space and not an empty string. If the user enter an empty string or invalid character they will be asked to re-enter the string again:
I know how to check for a character in a string. I use this method
alpha ="abcdefghijklmnopqrstuvwxyz"
message= input("Enter message: ")
for i in message:
if i in alpha:
print i
Usually I will use the method below to check for invalid input, but it will not work for this case if I want to check for a character in a string. I can only use this to check if the message is empty
textOK = False
while not textOK:
message= input(prompt)
if len(message) == 0:
print("Message is empty)
else:
textOK= True
This will re prompt the user whenever they input an empty string. I have no idea how to combine the two method. In short, I want to check if my input only contains lower letters,periods, exclamation marks, and space. If it contains other special characters or numbers or is an empty string, user will be prompt to enter the message again. Please help!!