String Validators

Sort by

recency

|

1943 Discussions

|

  • + 0 comments
    def validate(s: str) -> None:
        """Print True for every condition the string fullfill, otherwise print False"""
        
        if not isinstance(s, str) or not s.strip():
            raise ValueError("Invalid input")
        if not (0 < len(s) < 1000):
            raise ValueError("Min 1 character, max 1000")
        
        for check in (str.isalnum, str.isalpha, str.isdigit, str.islower, str.isupper):
            print(any(check(c) for c in s))
    
    if __name__ == '__main__':
        s = input().strip()
        validate(s)
    
  • + 0 comments

    if name == 'main': s = input() print (any(c.isalnum() for c in s)) print (any(c.isalpha() for c in s)) print (any(c.isdigit() for c in s)) print (any(c.islower() for c in s)) print (any(c.isupper() for c in s))

  • + 0 comments
    if __name__ == '__main__':
        s = input()
        
        print(any([st.isalnum() for st in s]))
        print(any([st.isalpha() for st in s]))
        print(any([st.isdigit() for st in s]))
        print(any([st.islower() for st in s]))
        print(any([st.isupper() for st in s]))
    
  • + 0 comments
    for method in (
        'isalnum', 
        'isalpha', 
        'isdigit', 
        'islower',
        'isupper'):
        print(any([getattr(char,method)() for char in s]))
    
  • + 0 comments

    s=input() print(any(c.isalnum() for c in s)) print(any(c.isalpha() for c in s)) print(any(c.isdigit() for c in s)) print(any(c.islower() for c in s)) print(any(c.isupper() for c in s))