# Validating phone number in Python HackerRank Solution

#### ByBrokenprogrammers

Dec 10, 2022

Hello Programmers, In this post, you will know how to solve the Validating phone number in Python HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.

One more thing to add, donâ€™t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

## Validating phone number in Python HackerRank Solution

### Problem

Let’s dive into the interesting topic of regular expressions! You are given some input, and you are required to check whether they are valid mobile numbers.
A valid mobile number is a ten digit number starting with a 7, 8 or 9.
Concept :A valid mobile number is a ten digit number starting with a 7, 8 or 9.
Regular expressions are a key concept in any programming language. A quick explanation with Python examples is available here. You could also go through the link below to read more about regular expressions in Python.

#### Input Format :

The first line contains an integer N, the number of inputs.
N lines follow, each containing some string.

#### Constraints :

• 1 <= N <= 10
• 2 <= len(number) <= 15

#### Output Format :

For every string listed, print “YES” if it is a valid mobile number and “NO” if it is not on separate lines. Do not print the quotes.

2
9587456281
1252478965

YES
NO

### Validating phone number in Python HackerRank Solutions

import re
N = int(input())
for i in range(N):
number = input()
if(len(number)==10 and number.isdigit()):
output = re.findall(r"^[789]\d{9}\$",number)
if(len(output)==1):
print("YES")
else:
print("NO")
else:
print("NO")

Disclaimer: The above Problem (Validating phone number in Python) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.