• We just launched and are currently in beta. Join us as we build and grow the community.

How to Validate Email Address in Terminal Console using Python

ambi97

Tech Startup Consultant
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
132
Likes
192
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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. regex =

    r'\b

    [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.

    [A-Z|a-z]{2,7}\b

    '

  3. def

    check(

    email

    )

    :


  4. if

    (

    re

    .fullmatch

    (

    regex,

    email

    )

    )

    :
  5. print

    (

    "This is a valid email"

    )

  6. else

    :
  7. print

    (

    "Invalid Email"

    )

  8. ret =

    False

  9. while

    True

    :
  10. print

    (

    "\n

    ================= Validate Email Address =================\n

    \n

    "

    )


  11. email

    =

    input

    (

    "Enter email address: "

    )

  12. check(

    email

    )

  13. opt =

    input

    (

    "\n

    Do you want to try again?(yes/no): "

    )

  14. if

    opt.lower

    (

    )

    ==

    'yes'

    :
  15. ret=

    False
  16. elif

    opt.lower

    (

    )

    ==

    'no'

    :
  17. ret=

    True
  18. print

    (

    "Exiting program...."

    )

  19. else

    :
  20. print

    (

    "Please enter yes/no:"

    )
  21. break

  22. if

    ret ==

    False

    :
  23. 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:

how-to-validate-email-address-in-python-1.jpg

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


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,340

323,349

Top