Email Slicer separates username and domain from the given email address. An email slicer is a handy application for separating an email address’s username and domain name. In this post, we’ll show you how to develop a Python Email Slicer.
Email Slicer Project Python
The script was created with Python3 and the built-in functions in it. Follow the below steps
Step 1. Download Python
You only need Python to run this script. You can visit here to download Python.
Step 2. Write the following code
Write this code in a Python file or directly copy this code and save the file with the name and .py extension python EmailSlicer.py
import re
def isValidEmail(email):
# Regular expression for validating an Email
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
if(re.fullmatch(regex, email)):
return True
else:
return False
email = input("Enter your email id - ")
if isValidEmail(email):
username = email[0:email.index('@')]
domain = email[email.index('@')+1: ]
print("Username - ", username)
print("Domain - ", domain)
else:
print("Invalid Email!")
Step 3. Run the code
After saving the code double-click on the file to run the program or simply open Command Prompt and write the following command.
python3 EmailSlicer.py