-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.py
More file actions
38 lines (36 loc) · 1.24 KB
/
validator.py
File metadata and controls
38 lines (36 loc) · 1.24 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
def validate_string(value, allows_none=False, allows_empty=True, case_sensitive=False, acceptable_values=[]):
if value == '' and allows_empty == False:
return False
if value == None and allows_none == False:
return False
if len(acceptable_values) > 0:
if case_sensitive:
for ac in acceptable_values:
if ac == value:
break
else:
return False
else:
for ac in acceptable_values:
if ac.lower() == value.lower():
break;
else:
return False
return True
def validate_number(value, allows_none=False, allows_zero=True, allows_reals=True, allows_negatives=True,
allows_positives=True, acceptable_values=[]):
if value == 0 and allows_zero == False:
return False
if value == None and allows_none == False:
return False
if value < 0 and allows_negatives == False:
return False
if value > 0 and allows_positives == False:
return False
if len(acceptable_values) > 0:
for ac in acceptable_values:
if ac == value:
return True
else:
return False
return True