Email id checker
Here is a simple email ID checker script in Python:
import re
def check_email(email):
email_regex = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
if re.match(email_regex, email):
return True
else:
return False
email = input("Enter email ID: ")
if check_email(email):
print("Valid email ID")
else:
print("Invalid email ID")
This script uses a regular expression to check if the email ID is valid. The regular expression used is:
^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
This regular expression matches the following:
^
asserts the start of the line[a-zA-Z0-9_.+-]+
matches one or more of the following characters: letters (both uppercase and lowercase), numbers, dot (.), hyphen (-), underscore (_), plus sign (+)@
matches the @ symbol[a-zA-Z0-9-]+
matches one or more of the following characters: letters (both uppercase and lowercase), numbers, hyphen (-)\.
matches the dot (.) character[a-zA-Z0-9-.]+
matches one or more of the following characters: letters (both uppercase and lowercase), numbers, dot (.), hyphen (-)$
asserts the end of the line
If the email ID matches this regular expression, the function returns True
, otherwise it returns False
.
You can run this script and enter an email ID to check if it's valid or not.