-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputValidations.py
38 lines (37 loc) · 1.22 KB
/
inputValidations.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
import re #RegEx built-in library, imported to validate the license plate number
def checkInput(inputReceived, inputType):
inputIsCorrect=False
#region Regular Expressions
licensePlateRegEx=re.compile("[A-Z]{2,3}-[0-9]{4}")
"""
Ecuadorian license plate numbers could come in the next formats:
AAA-####
AA-####
"""
dateRegEx=re.compile("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)\d\d$")
"""
Date will be in the format DD/MM/YYYY
"""
timeRegEx=re.compile("^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$")
"""
Time will be used in the format 00:00 - 23:59
"""
#endregion
#region Validations
if (inputType == "License Plate"):
if licensePlateRegEx.match(inputReceived):
inputIsCorrect=True
else:
print("Invalid license plate number, please try again")
elif(inputType == "Date"):
if dateRegEx.match(inputReceived):
inputIsCorrect=True
else:
print("Invalid date, please try again")
elif(inputType == "Time"):
if timeRegEx.match(inputReceived):
inputIsCorrect=True
else:
print("Invalid time, please try again")
#endregion
return inputIsCorrect