I need to validate the user's name so it only contains letters. For this i am using a while true statement. I also want the username to be written to a text file once it is valid how would i change my code to do this. How would i change my code so if the user enters an invalid name they have to try again, and if it is valid it is written to a text file.
import re
name=(input("Please enter your name: "))
while name is None or not re.match("[A-z]",name):
print("Invalid name. Try again")
else:
filename = ("name");
with open (filename, "a") as f:
f.write (name + "\n")