top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

How to validate an email address using Python

Writer: chalamohamed93chalamohamed93

Email is a method of exchanging messages between people using. It is a widely-used communication medium that can also be used for signing up in the application. Keeping this in mind, lots of invalid emails can cause the use of high bandwidth resulting in an increase in cost. So, the email field should be verified. Python has a couple of methods to verify whether an email is valid or not.

In this post we will introduce one of the way to verify and validate Emails :

Using Python Regex


Python has a module named re (regular expression or regex). The re module provides a set of powerful regular expression facilities, which allows you to quickly check whether a given string matches a given pattern (using the match function), or contains such a pattern (using the search function).

We can simply call in our program as:


import re

To verify email, we will use re module one of the function called search, in the following code, we are utilising the re module along with the search() method (built-in function) include inside verify_email function which return a True or False and has one argument should be a string.


def verify_email(email): """function to verify email patterns""" verify = re.search(pattern, email) # check if verify email returns # Match email or None if verify: print("A valid email") else: print("Invalid one")


Finally, we should ask the user to enter an Email address, with the input built-in function and use the function above (verify_email) to validate the email.


email = input("Please write your email address :") verify_email(email)



Comments


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