test1.py
from tkinter import *
from tkinter import messagebox
from test.regex import datevalidation
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
def check():
txt = text.get()
dateResult=datevalidation(txt)
if dateResult==True:
messagebox.showinfo("Info","The date is valid")
else:
messagebox.showerror("Error","Invalid date")
text=Entry(app,font=("Times New Roman",16))
text.pack()
btn=Button(app,text="Check Date",font=("Times New Roman",16), command=check)
btn.pack()
app.mainloop()
regex.py
import re
# Function to validate Gender
def datevalidation(date):
# Regex to check valid date in yyyy-mm-dd format
regex=re.compile("^([0-9]{4}[-/]?((0[13-9]|1[012])"
"[-/]?(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])[-/]?31|02[-/]?(0[1-9]"
"|1[0-9]|2[0-8]))|([0-9]{2}(([2468][048]|[02468][48])|[13579][26])|"
"([13579][26]|[02468][048]|0[0-9]|1[0-6])00)[-/]?02[-/]?29)$")
if re.fullmatch(regex, date):
dateResult=True
else:
dateResult=False
return dateResult
Output