-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDataIsValid.py
More file actions
118 lines (97 loc) · 3.71 KB
/
DataIsValid.py
File metadata and controls
118 lines (97 loc) · 3.71 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from copy import deepcopy
from re import fullmatch, sub, search
# from homework.Log import validerr
def nameReal(name_):
pattern = "[0-9]"
name = sub(pattern, "", name_)
if len(name)==0:
return False
return name
def dateIsReal(date):
year = int(date[:4])
if year < 1900 or year > 2020:
# validerr.paterr.warning(["It should be: 1900<year<=2020. Your year: ", year])
return False
month = int(date[5:7])
if month < 0 or month > 12:
# validerr.paterr.warning(["It should be: 0<month<=12. Your month: ", month])
return False
day = int(date[8:])
if day < 1 or day > 31:
# validerr.paterr.warning(["It should be: 0<day<32. Your day: ", day])
return False
if month == 2 and day > 29:
# validerr.paterr.warning("In Feb only 28 or 29 days")
return False
if month == 2 and day == 29:
print("WOW!")
return date
def dateIsValid(date):
pattern1 = "\d{4}.\d{2}.\d{2}" # y-m-d
pattern2 = "\d{2}.\d{2}.\d{4}" # d-m-y
match1 = fullmatch(pattern1, date)
match2 = fullmatch(pattern2, date)
if match1:
return dateIsReal(date)
elif match2:
dateNew = deepcopy(date[len(date) - 4:])
dateNew = '-'.join([dateNew, date[len(date) - 7:len(date) - 5]])
dateNew = '-'.join([dateNew, date[:2]])
if dateIsReal(dateNew):
return dateNew
else:
return False
else:
return False
# print(dateIsReal("1978-01-05"))
def phoneIsValid( phone_):
pattern = "[^+,0,1,2,3,4,5,6,7,8,9]"
phone = sub(pattern, "", phone_)
if len(phone)<10:
return False
if phone[0] == '8' or phone[0]=='7':
phone = ''.join(['+7', phone[1:]])
elif not phone[0] == '+' or not phone[1] == '7':
# validerr.paterr.warning(["Only Russians numbers are valid. +7-xxx-xxx-xx-xx or 8-xxx-xxx-xx-xx. Your num: ", phone])
return False
if not len(phone) == 12:
# validerr.paterr.warning(["Only Russians numbers are valid. len !=12 . Your num: ", phone])
return False
if not (phone[2:5] == '495' or phone[2:5] == '499' or phone[2] == '9'):
# validerr.paterr.warning(["Only Russians numbers are valid. +7-499-... or +7-495-... or +7-9..-.... Your num: ", phone])
return False
return phone
def docTypeIsValid(doc_type):
if not isinstance(doc_type, str):
return False
doc_type = doc_type.lower()
passport = "паспорт"
passportruen = "gfcgjhn"
zPassport = "загран"
zpassportruen = "pfuhfy"
prav1 = "водительск"
prav1ruen = "djlbntkmcr"
prav2 = "права"
prav2ruen = "ghfdf"
if search(zPassport, doc_type) or search(zpassportruen, doc_type):
return "загран"
elif search(passport, doc_type) or search(passportruen, doc_type):
return "паспорт"
elif search(prav1, doc_type) or search(prav2, doc_type) or search(prav1ruen, doc_type) or search(prav2ruen,
doc_type):
return "права"
return False
def docIdIsValid(id, type=None):
pattern = "[^0,1,2,3,4,5,6,7,8,9]"
id = sub(pattern, "", id)
if len(id) == 10:
if type == "паспорт" or type == "права" or not type:
return id
else:
# validerr.paterr.warning(["Zpass - len ==9. In dr and pass-10. Your type: ", type, ". Your id: ", id])
return False
elif len(id) == 9 and (type == "загран" or not type):
# validerr.paterr.warning(["Zpass - len ==9. In dr and pass-10. Your type: ", type, ". Your id: ", id])
return id
else:
return False