Skip to content

Commit 78fb8ac

Browse files
authored
Create emails_elif_gulseren.py
1 parent 25bda4d commit 78fb8ac

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎Week05/emails_elif_gulseren.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import re
2+
3+
class Emails(list):
4+
def __init__(self, emails=None):
5+
if emails is None:
6+
emails = []
7+
8+
valid_emails = []
9+
for email in emails:
10+
if self.validate(email):
11+
if email not in valid_emails:
12+
valid_emails.append(email)
13+
14+
super().__init__(valid_emails)
15+
16+
self.data = self
17+
18+
def validate(self, email):
19+
if not isinstance(email, str):
20+
raise ValueError("Bütün e-posta adresleri metin (string) formatında olmalıdır.")
21+
22+
pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
23+
if not re.match(pattern, email):
24+
raise ValueError(f"Geçersiz e-posta formatı: {email}")
25+
26+
return True
27+
28+
def __repr__(self):
29+
return super().__repr__()
30+
31+
def __str__(self):
32+
return super().__str__()

0 commit comments

Comments
 (0)