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.- import re
- regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
- def check(email):
- if(re.fullmatch(regex, email)):
- print("This is a valid email")
- else:
- print("Invalid Email")
- ret = False
- while True:
- print("\n================= Validate Email Address =================\n\n")
- email = input("Enter email address: ")
- check(email)
- opt = input("\nDo you want to try again?(yes/no): ")
- if opt.lower() == 'yes':
- ret=False
- elif opt.lower() == 'no':
- ret=True
- print("Exiting program....")
- else:
- print("Please enter yes/no:")
- break
- if ret == False:
- 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
Add new comment
- 76 views