From 530cd97f44bbc62e6a430e69b39c103a65558b64 Mon Sep 17 00:00:00 2001 From: gktgkayac <230315009@ogr.cbu.edu.tr> Date: Sat, 14 Nov 2026 20:35:09 +0300 Subject: [PATCH] Add Emails class for email validation and storage Implement an Emails class to validate and store unique email addresses. --- Week05/emails_goktug_kayaci.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Week05/emails_goktug_kayaci.py diff --git a/Week05/emails_goktug_kayaci.py b/Week05/emails_goktug_kayaci.py new file mode 100644 index 00000000..d06259a6 --- /dev/null +++ b/Week05/emails_goktug_kayaci.py @@ -0,0 +1,32 @@ +import re + + +class Emails(list): + + def __init__(self, emails): + self.data = [] + + for email in emails: + self.validate(email) + + if email not in self.data: + self.data.append(email) + + super().__init__(self.data) + + def validate(self, email): + if not isinstance(email, str): + raise ValueError("Email must be a string") + + pattern = r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$" + + if not re.fullmatch(pattern, email): + raise ValueError("Invalid email address") + + return True + + def __repr__(self): + return f"Emails({self.data!r})" + + def __str__(self): + return ", ".join(self.data)