A simple yet effective Python program that checks whether an email is valid based on multiple conditions including syntax, characters, and domain rules. It gives specific error codes and reasons for invalid inputs, helping users understand what went wrong.
This email validation program can perform the following validations:
- Detects if the first letter of the email is alphabetic.
- Counts the number of @ signs β ensures thereβs exactly one.
- Checks for allowed top-level domains:
.comand.in. (More can be added manually.) - Ensures only
.comor.inare used as domains. - Disallows emails that contain:
- Spaces
- Underscores (
_) - Extra dots (
.not in domain) - Capital letters
- Provides specific error messages with error codes when invalid.
- Asks the user to input:
1to get a detailed reason for the invalid email0to exit the program
- Python β Core programming logic
- No external libraries β Simple input, conditionals, and string functions
- Minimum 6 characters long
- Starts with a letter
- Contains exactly 1 '@'
- Ends with '.com' or '.in'
- Contains only lowercase alphabets, numbers, and allowed symbols (
@,., no spaces or uppercase)
Each invalid case is linked to a specific error number:
Error 1β Too shortError 2β First character not a letterError 3β Zero or multiple@Error 4β Missing domain or space at the endError 5β Contains space, capital letters, or invalid characters
- Used character-by-character inspection for email input
- Applied conditions with logical operators and flags
- Integrated user-driven error feedback
- Gained better understanding of valid email syntax rules
Enter your Email:
> g@g.com
Right Email!
Enter your Email:
> 9g@.com
Email incorrect!
Error number: 2
Enter 1 for error detail and enter 0 to exit the email checking:
> 1
Error number:2
Which means that your email address' first letter is a non-alphabatic or it is a space
Which is not valid.# Save the code in a file called email_validator.py and run it using:
python email_validator.py
This project is licensed under the MIT License. See the LICENSE file for full details.