test1.py
from tkinter import *
from tkinter import messagebox
from test.regex import namevalidation
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
def check():
txt = text.get()
nameResult=namevalidation(txt)
if nameResult==True:
messagebox.showinfo("Info","The name is valid")
else:
messagebox.showerror("Error","Invalid name")
text=Entry(app,font=("Times New Roman",16))
text.pack()
btn=Button(app,text="Check Name",font=("Times New Roman",16), command=check)
btn.pack()
app.mainloop()
regex.py
import re
def namevalidation(name):
regex=re.compile("^([a-zA-Z]{2,}\s[a-zA-Z]{1,}'?-?[a-zA-Z]{2,}\s?([a-zA-Z]{1,})?)")
if re.fullmatch(regex, name):
nameResult=True
else:
nameResult=False
return nameResult
Output