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:


Here is complete python program to compare email address.

import re def isValid(email): if(re.match("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$", email) != None): return True return False if(isValid("") == True): print("This is a valid email address") else: print("This is not a valid email address")


This is a valid email address

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


Add Comment