-
Notifications
You must be signed in to change notification settings - Fork 0
/
validations.py
40 lines (32 loc) · 991 Bytes
/
validations.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
import re
from datetime import time
name_pattern = '^[a-zA-Z]{2,30}$'
email_pattern = "^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
password_pattern = '^.{1,30}$'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
def is_valid_name(inpt):
if inpt is not None and re.match(name_pattern,inpt):
return True
return False
def is_valid_email(inpt):
if inpt is not None and re.match(email_pattern,inpt):
return True
return False
def is_valid_pass(inpt):
if inpt is not None and re.match(password_pattern,inpt):
return True
return False
def is_valid_number(inpt):
return True
'''
if inpt is not None and re.match(number_pattern,inpt):
return True
return False
'''
def defaultconverter(o):
if isinstance(o, time):
return o.__str__()
def is_valid_filename(filename):
if '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS:
return True
return False