0
0
Flaskframework~30 mins

Email verification pattern in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Email verification pattern
📖 Scenario: You are building a simple Flask web app where users can register with their email addresses. To ensure the email is valid, you want to implement an email verification pattern.This project guides you through setting up the data, configuration, core logic, and completion of the email verification feature.
🎯 Goal: Build a Flask app that accepts user email input, checks if the email format is valid using a regular expression, and displays a message indicating whether the email is valid or not.
📋 What You'll Learn
Create a Flask app with a route to accept email input
Use a regular expression to verify the email format
Display a success message if the email is valid
Display an error message if the email is invalid
💡 Why This Matters
🌍 Real World
Email verification is a common feature in web apps to ensure users provide valid contact information before accessing services.
💼 Career
Understanding how to implement email validation and user input handling in Flask is essential for backend web development roles.
Progress0 / 4 steps
1
DATA SETUP: Create a Flask app and import necessary modules
Write code to import Flask, request, and render_template from flask. Then create a Flask app instance called app.
Flask
Need a hint?

Use app = Flask(__name__) to create the app instance.

2
CONFIGURATION: Define a regular expression pattern for email validation
Create a variable called email_pattern and assign it the regular expression string r"^[\w\.-]+@[\w\.-]+\.\w+$" to match valid email formats.
Flask
Need a hint?

The regex checks for characters before and after '@' and a domain suffix.

3
CORE LOGIC: Create a route to handle email input and validate it
Write a Flask route for '/' that accepts GET and POST methods. Inside the route function verify_email, get the email from request.form with key 'email'. Use the re module to check if the email matches email_pattern. Return render_template('result.html', message=message) where message is 'Valid email!' if it matches or 'Invalid email!' if not.
Flask
Need a hint?

Use @app.route decorator and request.form.get('email', '') to get the email.

4
COMPLETION: Add the HTML template to display the email input form and result message
Create a simple HTML form in a file named templates/result.html that shows an input field named email and a submit button. Below the form, display the message variable passed from Flask inside a paragraph tag.
Flask
Need a hint?

Use a form with method POST and display the message variable inside a paragraph.