test1.py
from tkinter import *
from tkinter import messagebox
from test.regex import creditvalidation
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
def check():
txt = text.get()
creditResult=creditvalidation(txt)
if creditResult==True:
messagebox.showinfo("Info","The credit number is valid")
else:
messagebox.showerror("Error","Invalid credit number")
text=Entry(app,font=("Times New Roman",16))
text.pack()
btn=Button(app,text="Check Credit",font=("Times New Roman",16), command=check)
btn.pack()
app.mainloop()
regex.py
import re
def creditvalidation(credit):
regex=re.compile("(?:[0-9]{4}-){3}[0-9]{4}|[0-9]{16}")
if re.fullmatch(regex, credit):
creditResult=True
else:
creditResult=False
return creditResult
Output