def test_email(): addresses = ( # valid "*****@*****.**", "cust/[email protected]", # /, = are valid characters "!def!xyz%[email protected]", # !, % "*****@*****.**", # + is allowed "!#$%&*+-/=?^_`{}|[email protected]", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", '"Abc@def"@example.com', # @ in " " '"bert\ ernie"@w00t.com', # blank allowed, if in " " and '"\ \\""@dot.org', '"()<[:@\\"-/=?^_`{}|~.a"@ab.org', '""@example.org', "a@[10.10.10.10]", # theoretically valid, but not recognized 'abc."defghi"*****@*****.**', # dot-separated quoted string, not commonly used "b@[IPv6:2001:db8:1ff::a0b:dbd0]", # IP address literal as IPv6 "postbox@com", # top-level domains are valid hostnames # not valid "A@b@[email protected]", 'a"b(c)d,e:f;g<h>i[[email protected]', 'abc"defghi"*****@*****.**', " not\ [email protected]", "*****@*****.**", "*****@*****.**", "test [email protected]", "*****@*****.**", # two consectutive dots '"bert ernie"@w00t.com', "Abc\@[email protected]", # escaping @ only in " " allowed "lulz", "foo@bar", # bar is no top-level domain "foo@bar com", "foo@hello bar.com", "foo@[hello bar].com", "abcdefghijklmno@pqrstuvwxyz", ) validator = Validator() for email in addresses: if validator.validate_email(email, False): validated = "valid" else: validated = "not valid" print ("{0:32} {1:10}".format(email, validated))