diff --git a/Address_Validator_Improved/README.md b/Address_Validator_Improved/README.md new file mode 100644 index 00000000..c690e773 --- /dev/null +++ b/Address_Validator_Improved/README.md @@ -0,0 +1,57 @@ +# πŸ“§ Improved Email Validator + +This project provides a structured email validation script written in Python. +It improves upon simple checks (like just searching for `@` and `.`) by applying multiple +rules to accurately determine whether an email address is correctly formatted. + +--- + +## πŸš€ Features + +### βœ” 1. Validates correct ordering of `@` and `.` +- Ensures `.` appears **after** `@`. +- Prevents invalid formats like: + - `abc.gmail@com` + - `@gmail.com` + - `abc@gmail.` + +### βœ” 2. Checks proper placement of characters +- Local part (before @) must not be empty. +- Domain must have a valid extension (like `.com`, `.in`, `.org`). + +### βœ” 3. Handles spaces, dots, and case sensitivity +- Strips leading/trailing spaces. +- Converts email to lowercase. +- Detects consecutive dots such as `abc..xyz@gmail.com`. + +### βœ” 4. Provides detailed error messages +Instead of printing just β€œinvalid”, the validator explains *why* the email is invalid. + +### βœ” 5. Uses regex + rule-based logic +A hybrid approach ensures both flexibility and safety. + +--- + +## πŸ§ͺ Example Output +### Input + +abc@gmail.com + +### Output + +βœ“ Email is valid! + +### Input + +@domain.com + +### Output + +βœ— Email is invalid due to: + - Email must contain text before '@'. + - Email contains invalid characters or structure. + +## How to Run + +```bash +python email_validator.py \ No newline at end of file diff --git a/Address_Validator_Improved/address_validator_improved.py b/Address_Validator_Improved/address_validator_improved.py new file mode 100644 index 00000000..713e4bf0 --- /dev/null +++ b/Address_Validator_Improved/address_validator_improved.py @@ -0,0 +1,75 @@ +import re + +def validate_email(email: str) -> dict: + + result = { + "original_email": email, + "is_valid": True, + "errors": [] + } + + email = email.strip().lower() + + # Rule 1: Email must not be empty + if not email: + result["is_valid"] = False + result["errors"].append("Email cannot be empty.") + return result + + # Rule 2: Must contain exactly one '@' + if email.count("@") != 1: + result["is_valid"] = False + result["errors"].append("Email must contain exactly one '@' symbol.") + return result + + local_part, domain_part = email.split("@") + + # Rule 3: Local part must not be empty + if not local_part: + result["is_valid"] = False + result["errors"].append("Email must contain text before '@'.") + + # Rule 4: Domain part must contain at least one '.' + if "." not in domain_part: + result["is_valid"] = False + result["errors"].append("Email must contain at least one '.' after '@'.") + return result + + # Rule 5: Domain extension must be present + domain_name, *extensions = domain_part.split(".") + if not domain_name: + result["is_valid"] = False + result["errors"].append("Domain name cannot start with a dot.") + + if any(ext == "" for ext in extensions): + result["is_valid"] = False + result["errors"].append("Email cannot end with a dot or contain empty extensions.") + + # Rule 6: Prevent consecutive dots + if ".." in email: + result["is_valid"] = False + result["errors"].append("Email cannot contain consecutive dots '..'.") + + # Rule 7: Basic character whitelist + allowed_pattern = r"^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,}$" + if not re.match(allowed_pattern, email): + result["is_valid"] = False + result["errors"].append("Email contains invalid characters or structure.") + + return result + + +if __name__ == "__main__": + print("------ Improved Email Validator ------") + user_email = input("Enter an email address: ") + + response = validate_email(user_email) + + if response["is_valid"]: + print("\nβœ“ Email is valid!") + else: + print("\nβœ— Email is invalid due to:") + for err in response["errors"]: + print(f" - {err}") + + diff --git a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744 b/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744 new file mode 100644 index 00000000..e69de29b diff --git a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 b/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 deleted file mode 100644 index f5611fcf..00000000 Binary files a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 and /dev/null differ