How to check if a string contains capital letter, lower case letter, number and minimum length in Python

1 Answer

0 votes
def check_valid_string(s):
    msg = []
    if not any(ch.isupper() for ch in s):
        msg.append('String must have 1 upper case character')
    if not any(ch.islower() for ch in s):
        msg.append('String must have 1 lower case character')
    if not any(ch.isdigit() for ch in s):
        msg.append('String must have 1 number')
    if len(s) < 10:
        msg.append('String length should be at least 10')    
    if not msg:
        return True
     
    print(msg)        
     
    return False
     
 
password = "Python!@#"
 
print(check_valid_string(password))
 
 
 
  
'''
run:
 
['String must have 1 number', 'String length should be at least 10']
False
  
'''

 



answered Sep 14, 2021 by avibootz
edited Sep 14, 2021 by avibootz
...