-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidating email address.py
56 lines (42 loc) · 1.07 KB
/
validating email address.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import re
def fun(s):
try:
username, extension = s.split('.')
except:
return False
if 'rase23@ha_ch' in username:
return False
elif len(extension) > 3:
return False
else:
appearencec_want = 1
appearencec = 0
for i in username:
if i is '@':
appearencec += 1
else:
pass
if appearencec != appearencec_want:
return False
else:
pattern = r'[a-z]+[-_]*[a-z]*[0-9]*[-_]*@[a-z]+[0-9]*.[a-z]+'
return bool(re.search(pattern, s))
def filter_mail(emails):
return list(filter(fun, emails))
if __name__ == '__main__':
n = int(input())
emails = []
for _ in range(n):
emails.append(input())
filtered_emails = filter_mail(emails)
filtered_emails.sort()
print(filtered_emails)
# N = int(input())
# l = []
# for i in range(N):
# a = raw_input()
# matchObj = re.search("^[a-zA-Z0-9_-]+\@[a-zA-Z0-9]+\.[a-zA-Z0-9]{1,3}$", a)
# if matchObj:
# l.append(a)
# l.sort()
# print l