import re
username = input("Enter your name to start the test: ")
#Prompting the user to input their name
valid = re.match("^[A-Za-z]*$",username)
#A validation of letters only being used
if not valid:
print("Error! Letters only!")
username = input("Enter your name: ")
Asked
Active
Viewed 55 times
0

Avinash Raj
- 172,303
- 28
- 230
- 274

InvisibleMale
- 1
- 1
-
3read the doc for `while` – Avinash Raj Feb 03 '16 at 12:13
-
You're accepting an empty string as a valid username? – khelwood Feb 03 '16 at 12:21
2 Answers
0
why not use a while loop with your condition. Something like this, you fill in the details:
username = input("Enter your name to start the test: ")
while not re.match("^[A-Za-z]*$",username):
print("Error! Letters only!")
username = input("Enter your name: ")

shisui
- 195
- 1
- 7
0
Try this:
import re
valid = False
while not valid:
username = input("Enter your name to start the test: ")
valid = re.match("^[A-Za-z]*$", username)
if not valid:
print("Error! Letters only!")

Jan Pomikálek
- 1,369
- 2
- 13
- 22