test1.py
from tkinter import *
from tkinter import messagebox
from test.regex import mobilevalidation
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
def check():
txt = text.get()
creditResult=mobilevalidation(txt)
if creditResult==True:
messagebox.showinfo("Info","The mobile number is valid")
else:
messagebox.showerror("Error","Invalid Mobile number")
text=Entry(app,font=("Times New Roman",16))
text.pack()
btn=Button(app,text="Check Mobile",font=("Times New Roman",16), command=check)
btn.pack()
app.mainloop()
regex.py
import re
def mobilevalidation(mobile):
regex=re.compile("^(?:0|\+?977)\s?(?:\d\s?){9,11}$")
if re.fullmatch(regex, mobile):
mobileResult=True
else:
mobileResult=False
return mobileResult
Output