0
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: ")
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274

2 Answers2

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