Validating Email Addresses With a Filter

  • + 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