Validating Email Addresses With a Filter

  • + 0 comments
    def fun(s):
    
        try:
            username, rest = s.split('@')
            websitename, extension = rest.split('.')
            
        except ValueError:
            return False
        
        if not username.replace('-', '').replace('_', '').isalnum():
            return False
            
        if not websitename.isalnum():
            return False
            
        if not extension.isalpha() or not (1 <= len(extension) <= 3):
            return False
    
        return True