Validate Email Using Regex

Validate email format specifically through regex on a string.

IntermediateTopic: String Programs
Back

Python Validate Email Using Regex Program

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

Try This Code
# Program to validate email using regex

import re

email = input("Enter email: ")

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

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

Understanding Validate Email Using Regex

Another example of using regular expressions to validate an email-like pattern.

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