How to Validate Email Address in Terminal Console using Python

In this tutorial, we will learn how to program "Email Address Validation in the Terminal Console using Python." We will check whether the entered email address is valid or not. The objective is to safely and accurately validate the entered email address. A sample program will be provided to demonstrate the coding process.

This topic is very easy to understand. Just follow the instructions I provide, and you'll be able to do it yourself with ease. The program I’ll show you demonstrates the proper way to validate an email address. I’ll also provide a simple and efficient method to achieve this. So, let's start coding!

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. import re
  2.  
  3. regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
  4.  
  5. def check(email):
  6.  
  7.  
  8.     if(re.fullmatch(regex, email)):
  9.         print("This is a valid email")
  10.  
  11.     else:
  12.         print("Invalid Email")
  13.  
  14. ret = False
  15.  
  16. while True:
  17.     print("\n================= Validate Email Address =================\n\n")
  18.  
  19.  
  20.     email = input("Enter email address: ")
  21.  
  22.     check(email)
  23.  
  24.     opt = input("\nDo you want to try again?(yes/no): ")
  25.  
  26.     if opt.lower() == 'yes':
  27.         ret=False
  28.     elif opt.lower() == 'no':
  29.         ret=True
  30.         print("Exiting program....")
  31.  
  32.     else:
  33.         print("Please enter yes/no:")
  34.         break
  35.  
  36.     if ret == False:
  37.         continue

This script validates an email address using a regular expression (regex). The regex checks for a valid format, including the presence of an '@' symbol and a valid domain extension (like .com, .org, etc.).

The program asks the user to input an email address and checks it against the regex. If the email is valid, it prints "This is a valid email." If not, it prints "Invalid Email."

After each check, the user can either continue by typing "yes" or exit the program by typing "no."

Output:

There you have it we successfully created How to Validate Email Address in Terminal Console using Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment