-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck Validate E-Mail Address in Python .py
47 lines (44 loc) · 2.07 KB
/
Check Validate E-Mail Address in Python .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Prompt the user to enter an email address
email = input("Enter your email: ") # Example: [email protected]
# Initialize flags for various checks
k, j, d = 0, 0, 0 # k: space check, j: uppercase letter check, d: invalid character check
# Check if the email length is at least 6 characters
if len(email) >= 6:
# Check if the first character is a letter
if email[0].isalpha():
# Check if the email contains exactly one "@" symbol
if "@" in email and email.count("@") == 1:
# Check if the email ends with a valid domain (.xyz or .abc)
if email[-4] == "." or email[-3] == ".":
# Loop through each character in the email
for i in email:
# Check if the character is a space
if i.isspace():
k = 1
# Check if the character is a letter
elif i.isalpha():
# Check if the letter is uppercase
if i.isupper():
j = 1
# Check if the character is a digit (valid in an email)
elif i.isdigit():
continue
# Check if the character is one of the allowed special characters
elif i in ["_", ".", "@"]:
continue
# If the character is not valid, set the invalid character flag
else:
d = 1
# If any of the invalid conditions are met, print an error
if k == 1 or j == 1 or d == 1:
print("Wrong Email 5") # Space, uppercase, or invalid character detected
else:
print("Email is valid") # All checks passed
else:
print("Wrong Email 4") # Domain format is invalid
else:
print("Wrong Email 3") # Missing or multiple '@' symbols
else:
print("Wrong Email 2") # First character is not a letter
else:
print("Wrong Email 1") # Email length is too short