From 73fd108beae0b4933881d14363dec6d24b0fd451 Mon Sep 17 00:00:00 2001 From: "Brendan (Drendos)" <124395674+devDrendos@users.noreply.github.com> Date: Sat, 25 Jan 2025 19:13:25 -0500 Subject: [PATCH 1/2] Add .DS_Store to .gitignore --- Address Validator/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 Address Validator/.gitignore diff --git a/Address Validator/.gitignore b/Address Validator/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/Address Validator/.gitignore @@ -0,0 +1 @@ +.DS_Store From 8cfb4b637d5886bb8ebacc24af3786bba0086bda Mon Sep 17 00:00:00 2001 From: "Brendan (Drendos)" <124395674+devDrendos@users.noreply.github.com> Date: Sat, 25 Jan 2025 19:15:48 -0500 Subject: [PATCH 2/2] Added to and enhanced email address validation logic: added checks for '@' symbols and '.' positions. --- Address Validator/AddressValidator.py | 48 +++++++++++++++++++++------ 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/Address Validator/AddressValidator.py b/Address Validator/AddressValidator.py index 0dc49be1..b937067d 100644 --- a/Address Validator/AddressValidator.py +++ b/Address Validator/AddressValidator.py @@ -1,16 +1,42 @@ +import time + + +''' +Fixes: + - Now checks number of '@' symbols + - Now checks if characters come before and after the '@' symbol + - Now checks position of '.' +''' + def addressVal(address): - dot = address.find(".") - at = address.find("@") - if (dot == -1): - print("Invalid") - elif (at == -1): - print("Invalid") - else: - print("Valid") + """ + Validates an email address. + Ensures only one '@' is present, the '@' is the not the first char, + there is atleast one '.' after the '@', and the '.' is not the last + char in the email. + + Args: + address (str): The email to be validated. + Returns: + str: "Valid" if the email is valid, an invalid message otherwise. + """ + if '@' not in address or address.count('@') != 1: + return "Invalid: Email must contain exactly one '@' symbol!" + + at_pos = address.find('@') + dot_pos = address.find('.', at_pos) + + if at_pos == 0 or at_pos == len(address) - 1: + return "Invalid: Characters must appear before or after the '@'!" + + if dot_pos == -1 or dot_pos == len(address) - 1 or dot_pos < at_pos + 2: + return "Invalid: Dot must come after the '@'!" + + return "Valid" + print("This program will decide if your input is a valid email address") while(True): - print("A valid email address needs an '@' symbol and a '.'") x = input("Input your email address:") - - addressVal(x) + result = addressVal(x) + print(result)