0% found this document useful (0 votes)
3 views4 pages

Input Validation Form Using Python

The document outlines a Python program using Tkinter for a student registration form with input validation for username, telephone number, and password. It includes functions to validate each input and display success or error messages based on the validation results. Additionally, it establishes a connection to a MySQL database for potential data storage.

Uploaded by

temmybryan74
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Input Validation Form Using Python

The document outlines a Python program using Tkinter for a student registration form with input validation for username, telephone number, and password. It includes functions to validate each input and display success or error messages based on the validation results. Additionally, it establishes a connection to a MySQL database for potential data storage.

Uploaded by

temmybryan74
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INPUT VALIDATION FORM USING PYTHON

import tkinter as tk
from tkinter import messagebox
import re

def validate_username(username):
if len(username) <3:
return False, "Username must be at least 3 characters long."
if not [Link]():
return False, "Username must contain only letters and numbers."
return True, "Valid username."

def validate_tel_no(tel_no):
if not tel_no.isdigit():
return False, "Telephone number must contain only digits."
if len(tel_no) < 8 or len(tel_no) > 15:
return False, "Telephone number must be between 8 and 15 digits."
return True, "Valid telephone number."

def validate_password(password):
if len(password) < 6:
return False, "Password must be at least 6 characters long."
if not [Link](r"[A-Za-z]", password):
return False, "Password must contain at least one letter."
if not [Link](r"[0-9]", password):
return False, "Password must contain at least one number."
return True, "Valid password."

def submit_form():
username = entry_username.get()
tel_no = entry_tel.get()
password = entry_password.get()

u_valid, u_msg = validate_username(username)


t_valid, t_msg = validate_tel_no(tel_no)
p_valid, p_msg = validate_password(password)

if u_valid and t_valid and p_valid:


[Link]("Success", "Registration Successful!")
else:
errors = []
if not u_valid: [Link](u_msg)
if not t_valid: [Link](t_msg)
if not p_valid: [Link](p_msg)
[Link]("Error", "\n".join(errors))

# GUI Setup
root = [Link]()
[Link]("Student Registration Form")
[Link]("400x300")

# Labels and Entries


[Link](root, text="Username:").pack(pady=5)
entry_username = [Link](root)
entry_username.pack(pady=5)

[Link](root, text="Telephone Number:").pack(pady=5)


entry_tel = [Link](root)
entry_tel.pack(pady=5)

[Link](root, text="Password:").pack(pady=5)
entry_password = [Link](root, show="*")
entry_password.pack(pady=5)

# Submit Button
[Link](root, text="Submit", command=submit_form).pack(pady=20)

[Link]()

import [Link]

# Establish connection
conn = [Link](
host="localhost", # or your server IP
user="root", # your MySQL username
password="yourpassword",# your MySQL password
database="student_db" # the database you created
)

cursor = [Link]()

You might also like