Published on

How to Validate Email Address in Python

Authors

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