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.

#!/usr/bin/python

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("someone@example.com")) # returns True
print(is_email_valid("someone")) # returns False