Java, Python, Database, Flutter, Matlap, Micorcontroller, Tutorials, Swing Framework

Hancie e-Learning Studio

Learn Java, Learn HTML, CSS, PHP, Javascript, Python Tutorials || Download program source codes || Java Project and Source code available here || All types error troubleshooting tips available here

How to validate mobile number in Python Tkinter using regex?

 


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

Welcome all to Hancie e-learning studio
Friends,
I have brought an e-learning platform for you from where you can teach internet, website, programming language, error troubleshooting, etc. Blogger, WordPress templates, themes are available for free on this website, which are not charged for downloading, so that you can earn money by blogging using such templates and this is not a difficult task and this You can do it now. You keep uploading new posts by us and keep taking advantage of this website. The aim of which is to spread the knowledge related to internet, career, web designing and technology to the people and contribute to the development of the country.