How to Validate Email Address in Python

We often have a situation where we need to test whether the given string is a valid email address or not.

Here’s a quick post on how to it in no time.


import re
def is_email_valid( str ):
    email_regex = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
    return bool(re.match(email_regex,str))

print(is_email_valid("")) # returns True
print(is_email_valid("someone")) # returns False