Problem Name: Python - Validating phone numbers

Problem Link: 

In this HackerRank Functions in PYTHON problem solution,

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.


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.


1 <= N <= 100

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.

Sample Input


Sample Output








Code Examples

#1 Code Example with Python Programming

Code - Python Programming

import re

for _ in range(int(input())): print ("YES" if'^[789]\d{9}$', input()) is not None else "NO")
Copy The Code & Try With Live Editor


[Solved] Validating Roman Numerals in PYTHON solution in Hackerrank
[Solved] Validating and Parsing Email Addresses in PYTHON solution in Hackerrank