Validate Email Format

Validate whether a string matches a basic email address pattern.

IntermediateTopic: Conditional Programs
Back

Python Validate Email Format Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to validate email format using regex

import re

email = input("Enter an email address: ")

pattern = r"^[\w\.-]+@[\w\.-]+\.\w+$"

if re.match(pattern, email):
    print("Valid email format")
else:
    print("Invalid email format")
Output
Enter an email address: [email protected]
Valid email format

Understanding Validate Email Format

We use a simple regular expression to approximate valid email structure:

[email protected].

This demonstrates pattern matching and basic input validation with regex.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.

Table of Contents