File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1+ import re
2+
13class Emails (list ):
24 def __init__ (self , data : [str ]) -> None :
35 self .data = list (set (data ))
@@ -10,8 +12,18 @@ def __str__(self):
1012 return f"Emails: { self .data } "
1113
1214 def validate (self , data : [str ]) -> None :
15+ # Validate email addresses according to the pattern used by Gmail.
16+ # The local part (before the @) can contain:
17+ # - Alphanumeric characters
18+ # - Periods (.) but not consecutively or at the start/end
19+ # The domain part (after the @) can contain:
20+ # - Alphanumeric characters
21+ # - Periods (.) followed by at least two alphabetic characters
22+ # This pattern also supports subdomains.
23+ regex_pattern = r"^[A-Za-z0-9]+(?:[.][A-Za-z0-9]+)*@[A-Za-z0-9]+(?:\.[A-Za-z]{2,}){1,2}$"
24+
1325 for email in data :
1426 if isinstance (email , int ):
1527 raise ValueError ("Only string values accepted!" )
16- if "@" not in email :
28+ if not re . match ( regex_pattern , email ) :
1729 raise ValueError ("This is not an email adress!" )
You can’t perform that action at this time.
0 commit comments