top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Email Address Validity Checker using Python

Writer's picture: ayenadykyaw1ayenadykyaw1

Generally, to check the email address is valid, we have to look for '@' sign. Because every email address has @ sign. But specifically, we can check if the email is valid by looking at four parts which are name, @ sign, domain name, and top-level domain name.

For example. valid email address: johnDoe.123@gmail.com

  • johnDoe.123 -- name ( can include upper case/lower case letters, digits and some special characters )

  • followed by @ sign

  • gmail -- domain name ( can include upper case/lower case letters, hyphen and period)

  • .com -- top level domain ( can include at least two upper or lower case letters)

#ref: John Pollard, What are the rules for email address syntax? – Validity Help Center (returnpath.com)


So as for python program to check a valid email address, use python regular expression (https://github.com/python/cpython/tree/3.9/Lib/re.py) to make a pattern of valid email address. If the email matches with the pattern, then it will judge as a valid email address, if not it will judge as an invalid email address.

First we need to import re library.

import re

Then, create a regex pattern

pattern=r'[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}'

Check if the email matches with the pattern. If yes, print out as "Valid", otherwise print out as "Invalid"

    if re.search(pattern,email):
        print("Valid Email")
    else:
        print("Invalid Email")

The complete code snippet is as follow.

# Email Verifier...
import re
def emailVerifier(email):
    pattern=r'[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}'
    if re.search(pattern,email):
        print("Valid Email")
    else:
        print("Invalid Email")

To run this python function, just simply call the function name with one parameter which will be the email address you want to check.

1 comment

Recent Posts

See All

1 Comment


Data Insight
Data Insight
Sep 19, 2021

Very nice!

Like

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page