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

👋 I'm Ashik Nesin • Principal Software Engineer @Chargebee 👨‍💻• I write about web development & behinds the scenes of startup/side projects that I'm building

© 2022 Nesin Technologies LLP