Validating Email Addresses With a Filter

Sort by

recency

|

593 Discussions

|

  • + 0 comments
    import re
    
    def fun(s):
        # return True if s is a valid email, else return False
        pattern = r"^[\w-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$"
        if re.match(pattern, s) is None:
            return False
        else:
            return True
    
  • + 0 comments
    import re
    def fun(s):
        try:
                username = s.split('@')[0]
                sec_part = s.split('@')[1]
                websitename = sec_part.split('.')[0]
                extension = sec_part.split('.')[1]
        except Exception:
            return False
        
        reg_username = r'^[a-zA-Z0-9_-]+$'
        reg_websitenane = r'^[a-zA-Z0-9]+$'
        reg_extension = r'^[a-zA-Z]{1,3}+$'
    
    
        if re.match(reg_username, username) is not None and re.match(reg_websitenane, websitename) is not None and re.match(reg_extension, extension) is not None:
            return True
        else:
            return False
    
  • + 0 comments
    import re
    def fun(s):
        try:
                username = s.split('@')[0]
                sec_part = s.split('@')[1]
                websitename = sec_part.split('.')[0]
                extension = sec_part.split('.')[1]
        except Exception:
            return False
        
        reg_username = r'^[a-zA-Z0-9_-]+$'
        reg_websitenane = r'^[a-zA-Z0-9]+$'
        reg_extension = r'^[a-zA-Z]{1,3}+$'
    
    
        if re.match(reg_username, username) is not None and re.match(reg_websitenane, websitename) is not None and re.match(reg_extension, extension) is not None:
            return True
        else:
            return False
    
  • + 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
    
  • + 0 comments
    import re
    def fun(s):
        p = r"^[a-zA-Z0-9_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$"
        return bool(re.match(p, s))
    def filter_mail(emails):
        return list(filter(fun, emails))
    
    if __name__ == '__main__':
        n = int(input())
        emails = []
        for _ in range(n):
            emails.append(input())
    
    filtered_emails = filter_mail(emails)
    filtered_emails.sort()
    print(filtered_emails)