How to Validate Email Address in Python

April 19, 2016

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

👋 I'm Ashik Nesin • Sr. Frontend Engineer @Chargebee 👨‍💻• I write about modern Javascript & building web apps

© 2021 Nesin Technologies LLP