File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change
1
+ import re
2
+
1
3
class Emails (list ):
2
4
def __init__ (self , data : [str ]) -> None :
3
5
self .data = list (set (data ))
@@ -10,8 +12,18 @@ def __str__(self):
10
12
return f"Emails: { self .data } "
11
13
12
14
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
+
13
25
for email in data :
14
26
if isinstance (email , int ):
15
27
raise ValueError ("Only string values accepted!" )
16
- if "@" not in email :
28
+ if not re . match ( regex_pattern , email ) :
17
29
raise ValueError ("This is not an email adress!" )
You can’t perform that action at this time.
0 commit comments