-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidation.py
75 lines (68 loc) · 1.87 KB
/
validation.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import re
import datetime
#Validation function for Name, Last name, Patronymic.
def isValidName(name):
if name:
if not name.isalpha():
return False
elif not name[0].isupper():
return False
else:
return True
else:
return False
#Validation function for birth date.
def isValidBirthDate(date):
if date:
try:
datetime.datetime.strptime(date,"%Y/%m/%d")
return True
except:
try:
datetime.datetime.strptime(date,"%d/%m/%Y")
return True
except:
try:
datetime.datetime.strptime(date,"%m/%d/%Y")
return True
except:
return False
else:
return True
#Validation function for Phone number.
def isValidPhoneNumber(number):
if number:
if len(number) == 12 and number.startswith("+374") and number[1:].isnumeric():
return True
else:
return False
else:
return False
#Validation function for Email.
def isValidEmail(mail):
if mail:
invalidCharacters = ")(][}{><,?/\+:;'\"|~`!#$%^&*= "
for sign in invalidCharacters:
if sign in mail:
return False
if mail.startswith("-") or mail.startswith("_") or mail.startswith("@") or\
mail.startswith(".") or not mail.islower() or mail.count("@") != 1:
return False
else:
domainName = mail[mail.index("@")+1:]
if domainName.count(".") != 1 or domainName.count("_") != 0 or domainName.count("-") != 0:
return False
else:
return True
else:
return False
def isValidPrice(price):
if price:
num_format = re.compile(r"^\d\d*[,]?\d*[,]?\d*[.,]?\d*\d$")
it_is = re.match(num_format,str(price))
if it_is:
return True
else:
return False
else:
return False