Change language

Check if email address is correct or not in Python


When you receive the string, write a Python program to check if the string is a valid email address or not.

Email — it is a string (a subset of ASCII characters), separated into two parts by the @ symbol, "personal_info" and the domain, that is, personal_info @ domain.

Examples :

  Input:  [email protected]  Output:  Valid Email  Input:  [email protected]  Output:  Valid Email  Input:  Output:  Invalid Email 

In this program we use the search () method of the re module ... so let’s see a description about that. (): this method either returns None (if the pattern doesn’t match) or re.MatchObject which contains information about the corresponding part of the string. This method stops after the first match, so it is better suited for validating regular expressions than extracting data.

Let’s take a look at a Python email validation program:

# Python Email Checker

# import re module

# re module provides support
# for regular expressions

import re

# Make a regular expression
# to check email

regex = ’ ^ w + ([.-]? w +) * @ w + ([.-]? w +) * (. w {2,3}) + $ ’

# Define a function for
# to check email

def check (email): 


# pass a regular expression

# and a string in the search () method

if ( (regex, email)) : 

print ( "Valid Email"


< code class = "keyword"> else

print ( " Invalid Email "


Driver code

if __ name__ = = ’__main__’


# Enter your email address

email = "[email protected]"


# call the run function

check (email)


email = "[email protected]"

  check (email)


email = "ankitrai326 .com "

  check (email)


 Valid Email Valid Email Invalid Email 


Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method