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