-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidator.py
More file actions
95 lines (93 loc) · 3.06 KB
/
Copy pathvalidator.py
File metadata and controls
95 lines (93 loc) · 3.06 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
def checkstring(value):
restrict='1234567890!@#$%^&*()-_+=} {:][|\"\'\\|/?.><,'
for i in value:
flag=True
if i in restrict:
print('Invalid character used in name.')
flag=False
break
return flag
def checkpass(value):
restrict='-][,\)('
for i in value:
flag=True
if i in restrict:
print('Invalid character used in name.')
flag=False
break
return flag
def entry(title,vtype,ttype,size):
if vtype=='char':
value=input(title+' : ').strip()
if len(value)<3 or len(value)>size:
print('Invalid size, '+title+' must be 3 to '+str(size))
return None
elif checkstring(value):
return value.capitalize()
else:
return None
elif vtype=='string':
value=input(title+' : ').strip()
if len(value)<4 or len(value)>size:
print('Invalid size, '+title+' must be 4 to '+str(size))
return None
else:
return value.title().replace(' ','_')
elif vtype=='email':
value=input(title+' : ').strip()
if len(value)<10 or len(value)>size:
print('Invalid size, '+title+' must be 10 to '+str(size))
return None
elif '@' not in value:
print('Invalid '+title+' \'@\' missing.')
return None
else:
if value[value.find('@'):].count('.')==1:
if len(value[value.find('@'):][value[value.find('@'):].find('.'):]) >=3:
return value.lower()
else:
print('Invalid Domain.')
return None
elif vtype=='int' and ttype=='user':
value=int(input(title+' : '))
if len(str(value))==10:
return value
del title,vtype,ttype,size
else:
print('Invalid contact no.')
return None
elif vtype=='int' and ttype=='book':
if size==2:
value=int(input(title+' : '))
if value>0 and value<100:
return value
else:
print('Book limit exceed.')
return None
else:
value=int(input(title+' : '))
if len(str(value))>=9 and len(str(value))<=size:
return value
else:
print('ISBN error.')
return None
elif vtype=='select' and ttype=='user':
print('1 Student\n2 Staff')
choice=input('Enter a choice : ')
if choice=='1':
return 'Student'
elif choice=='2':
return 'Staff'
else:
return None
elif vtype=='select' and ttype=='book':
print('1 Reserved\n2 Non Reserved')
choice=input('Enter a choice : ')
if choice=='1':
return 'rserv'
elif choice=='2':
return 'nores'
else:
return None
else:
print('Invalid operation. Please restart ')