This should help:
import re
# Check if the string has 3 digits or more
def haveDigits(text):
if len(filter(str.isdigit, text))>=3:
return True
else:
return False
# Check if the string has 2 uppercase letters or more
def haveUppercase(text):
if len([char for char in text if char.isupper()])>=2:
return True
else:
return False
# First condition
print(haveDigits("hola123")) # True
print(haveDigits("hola12")) # False
# Second condition
print(haveUppercase("hHola")) # False
print(haveUppercase("HHHola")) # True
# Both conditions at the same time
def bothConditions(text):
if (haveUppercase(text) & haveDigits(text)):
return True
else:
return False
print(bothConditions("HHHola123")) # True
print(bothConditions("hola1")) # False
1
solved How to find if a string contains uppercase letters and digits [closed]