Validating Email Addresses With a Filter

Sort by

recency

|

596 Discussions

|

  • + 0 comments
    import re
    def fun(s):
        # return True if s is a valid email, else return False
        pattern = r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$'
        
        if (re.match(pattern, s)): return True
        else: return False
    
  • + 0 comments
    import re
    emailregex = re.compile(r'([a-zA-Z0-9_-]{1,})(@)([a-zA-Z0-9]+)(\.)([a-z|A-Z]{1,3})',re.VERBOSE)
    def fun(emails):
        return bool(emailregex.fullmatch(str(emails)))
    
    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)
    
  • + 0 comments
    import re
    
    def fun(s):
        result = re.fullmatch(r'[a-z0-9_-]+@[a-z0-9]+\.[a-z]{1,3}', s, re.I)
        
        return True if result else False
    
  • + 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