0

I'm currently working on a program that has a validation rule for a name, which doesn't allow any punctuation to be entered. The input is stored in a variable, name, and then stored in a file later on. I have already got the punctuation sorted out. However, when I went back to test my program, I realised that if I left the field blank, the program would accept my input. Here is that part of my code:

n = True
while n == True:
    name = input("\nPlease enter your name:\n")
    invalidName = re.search("[^A-Za-z]+",name)

    if invalidName:
        print("No special characters will be accepted.")
    else:
        print("Accepted.")
        name = name.lower()
        name = name.title()
        n = False

I would greatly appreciate it if someone came up with something to make it so that the user input must have something entered for the program to accept it.

Jamil
  • 1
  • 5

1 Answers1

1

Use:

elif not name:
    print("You must type something in!")

after the if statement

Gábor Erdős
  • 3,599
  • 4
  • 24
  • 56