Wednesday, August 9, 2023

Q2 :- Write a python program to validate an email address by using regular expression.

import re

 

def validate_email(email):

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

    if re.match(pattern, email):

        return True

    else:

        return False

 

# Test the program

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

 

if validate_email(email_to_validate):

    print("Valid email address")

else:

    print("Invalid email address")

No comments:

Post a Comment