Validate email address in Python

In this post, we will see how to validate email address in Python.

There are times when you want to validate email address. You can write your own code to validate email address but there are many regular expressions which you can use to validate email address.

We can use regular expression provided by OWASP Validation Regex Repository which is considered to be safe and will solve the purpose in most of the cases.

Here is the regular expression:

^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$

Here is complete python program to compare email address.

Output:

This is a valid email address

That’s all about how to validate email address in Python.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *