PYTHON 5 (1)
PYTHON 5 (1)
Roll no :- 08
Experiement no. 5
Aim:- Write a Python script that prompts the user to enter their phone number and email ID. It then
employs Regular
dard phone number and email address formats
Code:-
import re
phone_pattern = re.compile(r'^\+?\d{10,15}$')
email_pattern = re.compile(r'^[\w. -]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
if phone_pattern.match(phone):
print("Valid phone number")
else:
print("Invalid phone number")
if email_pattern.match(email):
print("Valid email ID")
else:
print("Invalid email ID")
Output :-
Experiement no. 5
Aim:- Write a Python script that prompts the user to enter apassword. Use regular expressions to validate
the password based on these
Criteria : Atleast 8 characters long, Contains at least one uppercase letter, one lowercase
letter, onedigit, and one special character
Code :-
import re
def check_password_strength(password):
pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$')
return bool(pattern.match(password))
if check_password_strength(password):
print("Strong password")
else:
print("Weak password. Must be at least 8 characters long, include uppercase, lowercase, digit, and
special character.")
Output :-