๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

phone number and email-id from the user and validate it

โ† All Python Programs

Aim:

☛   Write a python code to read a phone number and email-id from the user and validate it for correctness.

Solution :


PROGRAM: (validate_phmail.py)

 
import re
# Make a regular expression for validating an Email
regex = r'^\b[A-Za-z0-9._%+-]+[@]\w[A-Za-z]+[.]\w[A-Z|a-z]{2,5}$'
# Make a regular expression for validating a Phone Number
Pattern = '^\\+?[6-9][0-9]{9}$'
# Define a function for validating an Email
def is_check_email(email):
	if(re.fullmatch(regex,email)):
		print(" Valid Email - ID ")
	else:
		print(" Invalid Email - ID ")
# Define a function for validating a PHONE NUMBER
def is_check_Phone_number(mobile_no):
	if(re.search(Pattern,mobile_no)):
		print(" Valid Phone Number ")
	else:
		print(" Invalid Phone Number ")
# Driver Code
if __name__ == '__main__':
	email = input(" Enter your MAIL-ID = ")
	phone_number = input(" Enter your PHONE NUMBER = ")
	is_check_email(email)
	is_check_Phone_number(phone_number)

OUTPUT:

 
Sample Run 1:
------------
 Enter your MAIL-ID = study@gmail.com
 Enter your PHONE NUMBER = 9758456123
 Valid Email - ID
 Valid Phone Number

Sample Run 2:
------------
 Enter your MAIL-ID = study%are@gmail.com
 Enter your PHONE NUMBER = 1234567890
 Valid Email - ID
 Invalid Phone Number

Sample Run 3:
------------
 Enter your MAIL-ID = glance@gmail - 3 .com
 Enter your PHONE NUMBER = 8945621231
 Invalid Email - ID
 Valid Phone Number



๐Ÿ’ป Run This Python Program

phone number and email-id from the user and validate it
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals