1

I want the code to stop the person and say "hey its gotta be all lowercase" And then make them input it again until its all lowercase. I was trying something like this:

username=input("Enter username ")
while username[::] .upper():
    print("username cannot have capital letters")
    username = input("Enter username ")
Wayne
  • 660
  • 6
  • 16
  • 2
    I think your question title is incorrect. I believe it should be "How to not accept **upper** case letters as input?" – MikeH Jan 22 '20 at 16:42
  • `` import re username_re = re.compile(r"^[0-9]*[a-z]+[a-z0-9]*$") username=input("Enter username ") m = username_re.match(username) while not m: username=input("Enter username ") print("username cannot have capital letters") m = username_re.match(username) `` – MikeH Jan 22 '20 at 16:51

1 Answers1

2

You can use string.islower() for this:

username=input("Enter username ")
while not username.islower():
    print("username cannot have capital letters")
    username = input("Enter username ")

If you want to allow, for example, username = "@123", you could instead use

import string

username=input("Enter username ")
while any(c in string.ascii_uppercase for c in username):
    print("username cannot have capital letters")
    username = input("Enter username ")
CDJB
  • 14,043
  • 5
  • 29
  • 55
  • 2
    @CDJB i think its easier to just do `username == username.lower()` for your second example. `"@123".lower() == "@123"` evaluates to True – Grant Williams Jan 22 '20 at 16:45
  • @GrantWilliams also a valid option – CDJB Jan 22 '20 at 16:46
  • No this is perfect because I don't want to change there username because then people will think its capital when its not. thank you both so much for your help! – Wayne Jan 23 '20 at 17:02