phone number and email-id from the user and validate it
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.
Related Python Lab Programs
๐
Python Basics
1.
Use a web browser to go to Python website http://python.org. Start Python interpreter and type help().
View Solution โ
3.
Write a Python program to calculate compound interest for given principal amount, rate of interest and number of periods.
View Solution โ
4.
Write a Python program to read name, address, email and phone number through keyboard and print them.
View Solution โ
6.
Write a Python program to check whether the given input is a digit, lowercase letter, uppercase letter or special character.
View Solution โ
7.
Write a Python program to print all prime numbers in a given interval using break.
View Solution โ
๐
Arrays, Lists and Tuples
4.
Write a Python function is_sorted() to check whether the elements of a list are sorted.
View Solution โ
5.
Write a Python function has_duplicates() to check whether a list contains duplicate elements.
View Solution โ
6.
Write a Python function remove_duplicates() to remove duplicate elements from a list.
View Solution โ
๐ค
Strings and Dictionaries
1.
Write a Python program to add single-letter words such as I, a and an empty string to a given word list.
View Solution โ
3.
Write a Python program to add a comma between every character of a string. Example: Apple โ A,p,p,l,e.
View Solution โ
4.
Write a Python program to remove a given word from all occurrences in a string.
View Solution โ
5.
Write a Python function to capitalize the first letter of each word in a sentence and convert the remaining letters to lowercase without built-in functions.
View Solution โ
๐
Recursion and Matrices
1.
Write a recursive Python function to generate all binary strings of n-bit length.
View Solution โ
โ๏ธ
Modules, Exceptions and Classes
1.
Create a Python module and demonstrate its use with geometric shapes and operations.
View Solution โ
3.
Define draw_rectangle(Canvas, Rectangle) and write a Python program to draw a rectangle.
View Solution โ
4.
Add a color attribute to the Rectangle class and modify draw_rectangle() to draw a colored rectangle.
View Solution โ
6.
Create a Circle class and write a Python program with draw_circle() to draw a circle.
View Solution โ
๐
Validation and File Handling
3.
Write a Python program to open a file, check whether specified words are present and display the words when found.
View Solution โ
4.
Write a Python program to read a text file and find the word with the most number of occurrences.
View Solution โ
5.
Write a Python program to find the number of words, vowels, blank spaces, lowercase letters and uppercase letters in a text file.
View Solution โ
๐
Python Libraries, Logic Gates and GUI
3.
Write a Python program to implement Digital Logic Gates: AND, OR, NOT and EX-OR.
View Solution โ
4.
Create a GUI window wizard with two text labels, two text fields, Submit and Reset buttons.
View Solution โ