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.  

https://developers.google.com/edu/python/regular-expressions  

Input Format

The first line contains an integer $N$, the number of inputs.

$N$ lines follow, each containing some string.

Constraints  

$1\leq N\leq10$  

$2\leq len(Number)\leq15$  

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
2
9587456281
1252478965

Sample Output
YES
NO

Difficulty: EASY

Solutions:
import re
for i in range(int(input())):
	print('YES' if re.search('^[7-9]\\d{9}$', input()) else 'NO')


import re
n = int(input())
p = re.compile('[7-9]\\d{9}')
for i in range(n):
	s = input()
	if p.fullmatch(s):
		print('YES')
	else:
		print('NO')


import re
for t in range(int(input())):
	k = input()
	if len(k) != 10:
		print('NO')
	elif re.match('^[789][0-9]*$', k):
		print('YES')
	else:
		print('NO')


def main():
	pass
	n = int(input())
	while n != 0:
		n = n - 1
		str = input()
		f = 1
		g = 0
		l = len(str)
		k = 1
		i = 0
		while i < l:
			if str[i] < '0' or str[i] > '9':
				k = 0
			i = i + 1
		if l != 10:
			f = 0
		if str[0] == '7' or str[0] == '8' or str[0] == '9':
			g = 1
		if f == 1 and g == 1 and (k == 1):
			print('YES')
		else:
			print('NO')
main()


import re
N = int(input())
for test in range(N):
	number = str(input())
	match = re.search('^[789]\\d{9}$', number)
	if match:
		print('YES')
	else:
		print('NO')


import re
n = int(input())
for i in range(n):
	e = input()
	if re.match('^[0-9]*$', e):
		if (int(e[0]) == 7 or int(e[0]) == 8 or int(e[0]) == 9) and len(e) == 10:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import re

def isValid(s):
	if len(s) != 10:
		return False
	if not s[0] in ['7', '8', '9']:
		return False
	match = re.search('\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d', s)
	if match:
		return True
	return False
num = int(input())
for i in range(num):
	if isValid(input()):
		print('YES')
	else:
		print('NO')


import re
num = int(input())
for i in range(num):
	number = input()
	if re.match('[789]\\d{9}', number):
		if len(number) == 10:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def isvalid(s):
	s = list(s)
	a = ['7', '8', '9']
	if len(s) != 10 or s[0] not in a:
		print('NO')
		return
	for i in range(0, len(s)):
		try:
			s[i] = int(s[i])
		except ValueError:
			print('NO')
			return
	print('YES')
	return

def validate():
	n = int(input())
	for i in range(0, n):
		y = input()
		isvalid(y)
validate()


n = int(input())
d = 0
for i in range(n):
	try:
		c = input()
		d = int(c)
		if (c[0] > '6' and c[0] <= '9') and len(c) == 10:
			print('YES')
		else:
			print('NO')
	except:
		print('NO')


import re
p = re.compile('[7,8,9]{1}[0-9]{9}')
for _ in range(int(input())):
	number = input()
	if len(number) == 10:
		if p.match(number):
			print('YES')
			continue
	print('NO')


import re
n = int(input().strip())
for _ in range(n):
	tel = input().strip()
	pattern = '^[789][0-9]{9}$'
	print('{}'.format('YES' if bool(re.match(pattern, tel)) else 'NO'))


import re
n = int(input())
for i in range(n):
	s = input()
	if re.search('\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d', s) and len(s) == 10:
		if s[0] == '7' or s[0] == '8' or s[0] == '9':
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import decimal
import re
t = int(input())
n = 'NO'
y = 'YES'
while t > 0:
	t = t - 1
	pn = input()
	ln = len(pn)
	flg = 0
	macth = re.search('([A-Z])', pn)
	if ln != 10:
		flg = 0
	elif macth:
		flg = 0
	elif pn[:1] == '8':
		flg = 1
	elif pn[:1] == '9':
		flg = 1
	elif pn[:1] == '7':
		flg = 1
	if flg == 1:
		print('YES')
	else:
		print(n)


import sys, re
if sys.version_info[0] >= 3:
	raw_input = input
for i in range(int(raw_input())):
	print('YES' if re.match('^[7-9][0-9]{9}$', raw_input().rstrip()) else 'NO')


import re
pattern = re.compile('^[789]\\d{9}$')
N = int(input())
for n in range(N):
	print('YES' if pattern.match(input()) else 'NO')


import re
matchString = re.compile('^[7-9]{1}\\d{9}$')
nInputs = int(input())
while nInputs > 0:
	phoneNo = input()
	if matchString.match(phoneNo):
		print('YES')
	else:
		print('NO')
	nInputs -= 1


import re
N = int(input())
a = re.compile('([0-9]+)*$')
for i in range(0, N):
	phone_number = input()
	if len(phone_number) == 10:
		try:
			fNumber = int(phone_number[0])
			if fNumber == 7 or fNumber == 8 or fNumber == 9:
				if a.match(phone_number):
					print('YES')
				else:
					print('NO')
			else:
				print('NO')
		except ValueError:
			print('NO')
	else:
		print('NO')


import re
N = int(input())
for i in range(N):
	number = input().strip()
	m = re.search('^[7-9]\\d{9}$', number)
	if m:
		print('YES')
	else:
		print('NO')


import re
n = int(input())
for i in range(n):
	a = input()
	if re.search('^[789]\\d{9}', a) != None and len(a) == 10:
		print('YES')
	else:
		print('NO')


import re
test = int(input())
for case in range(test):
	phno = input()
	if len(phno) != 10:
		print('NO')
	else:
		match = re.match('^[7|8|9]\\d+$', phno)
		if match:
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(n):
	ph = input()
	if ph.isdigit() and len(ph) == 10 and (ph.startswith('7') or ph.startswith('8') or ph.startswith('9')):
		print('YES')
	else:
		print('NO')


from sys import stdin
import re

def main():
	N = int(stdin.readline())
	for i in range(N):
		number = stdin.readline().strip()
		match = re.fullmatch('[789]\\d{9}', number)
		if match == None:
			print('NO')
		else:
			print('YES')
main()


import re

def validatePhone(phone):
	m = re.match('^[7-9]\\d\\d\\d\\d\\d\\d\\d\\d\\d$', phone)
	return 'YES' if m else 'NO'
for i in range(int(input())):
	print(validatePhone(input()))


t = int(input())
for test in range(0, t):
	x = str(input())
	if len(x) != 10:
		print('NO')
	elif x.isdigit():
		if x.startswith('7') or x.startswith('8') or x.startswith('9'):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import re
n = int(input())
for i in range(n):
	l = input()
	m = re.match('^[789][0-9]{9}$', l)
	if m:
		print('YES')
	else:
		print('NO')


import re
numcases = int(input())
numbers = []
for i in range(numcases):
	number = input()
	if re.search('^[789](\\d{9})$', number):
		print('YES')
	else:
		print('NO')


import re
num = int(input())
start = {'7', '8', '9'}
for i in range(0, num):
	numb = input()
	if len(numb) == 10 and re.match('^[0-9]*$', numb) and (numb[0:1] in start):
		print('YES')
	else:
		print('NO')


import re
for i in range(int(input())):
	print('YES' if re.match('^[7-9][0-9]{9}$', input()) else 'NO')


import re
N = int(input())
for i in range(N):
	number = input()
	if re.search('^(7|8|9)\\d{9}$', number) != None:
		print('YES')
	else:
		print('NO')


import re
n = int(input())
phone = re.compile('[7-9][0-9]{9}')
for x in range(n):
	no = input()
	if len(no) == 10:
		if phone.search(no):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import re

def c(a):
	if not (a[0] == '7' or a[0] == '8' or a[0] == '9'):
		return 'NO'
	elif len(a) != 10:
		return 'NO'
	else:
		num = '0123456789'
		for i in a:
			if i not in num:
				return 'NO'
	return 'YES'
for i in range(int(input())):
	print(c(input()))


import re
for _ in range(0, int(input())):
	print('YES' if re.search('^[789]\\d{9}$', input()) else 'NO')


import sys
import re
n = int(sys.stdin.readline())
for i in range(0, n):
	str = sys.stdin.readline()
	if re.match('([7-9])(\\d{9})$', str) == None:
		print('NO')
	else:
		print('YES')


import re
t = int(input())
p = re.compile('(9|8|7)([0-9]){9}')
for i in range(t):
	pn = input()
	if p.match(pn) and len(pn) == 10:
		print('YES')
	else:
		print('NO')


import re
n = int(input())
p = re.compile('^[7-9]\\d{9}$')
for i in range(n):
	if p.search(input()):
		print('YES')
	else:
		print('NO')


import re
t = int(input())
for i in range(t):
	n = input()
	(a, b, c) = (False, False, True)
	if n[0] == '7' or n[0] == '8' or n[0] == '9':
		a = True
	if len(n) == 10:
		b = True
	if re.search('\\D', n):
		c = False
	if a and b and c:
		print('YES')
	else:
		print('NO')


import re
for _ in range(int(input())):
	if re.search('^[789]\\d{9}$', input()):
		print('YES')
	else:
		print('NO')


N = int(input())
for n in range(N):
	number = input()
	if number.isdigit() and len(number) == 10 and (number[0] == '7' or number[0] == '8' or number[0] == '9'):
		print('YES')
	else:
		print('NO')


import re
mregex = re.compile('^[789]\\d{9}$')
t = int(input())
for r in range(t):
	l = input()
	x = mregex.match(l)
	if x:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	num = input()
	a = True
	for i in num:
		if ord(i) not in range(48, 58):
			a = False
	if len(num) == 10 and (num[0] == '7' or num[0] == '8' or num[0] == '9') and a:
		print('YES')
	else:
		print('NO')


import re
numtel = int(input())
tel = []
for i in range(numtel):
	tel.append(input())
pat = '^[789][0-9]{9}$'
for telnumber in tel:
	match = re.search(pat, telnumber)
	if match:
		print('YES')
	else:
		print('NO')


import re
for i in range(int(input())):
	match = re.search('^[789]\\d{9}$', input())
	if match:
		print('YES')
	else:
		print('NO')


import re
num = int(input())
for i in range(num):
	phone = str(input())
	if len(phone) != 10:
		print('NO')
		continue
	if re.search('^[7-9]\\d\\d\\d\\d\\d\\d\\d\\d\\d', phone):
		print('YES')
	else:
		print('NO')


import re
n = int(input())
for _ in range(n):
	if re.match('^[789]\\d{9}$', input()):
		print('YES')
	else:
		print('NO')


import re
N = int(input())
for _ in range(N):
	if re.match('^[7-9][0-9]{9}$', input()):
		print('YES')
	else:
		print('NO')


import re
for i in range(int(input())):
	numb = input().strip()
	match = re.fullmatch('[789]\\d{9}', numb)
	if match:
		print('YES')
	else:
		print('NO')


import re
for _ in range(int(input())):
	number = input()
	match = re.match('^[789][0-9]{9}$', number)
	if match:
		print('YES')
	else:
		print('NO')


import re

def isPhoneNumber(s):
	return re.match('^[789][0-9]{9}$', s)
numbers = int(input())
for number in range(numbers):
	print('YES' if isPhoneNumber(input()) else 'NO')


import re
N = int(input())
robj = re.compile('^[7|8|9]\\d{9}$')
for i in range(0, N):
	number = input()
	m = robj.match(number)
	if m != None:
		print('YES')
	else:
		print('NO')


import re
n = int(input())
for i in range(n):
	print('YES' if re.match('[789]\\d{9}$', input()) else 'NO')


import re
N = int(input())
for x in range(0, N):
	S = input()
	match = re.search('[789]\\d+', S)
	if match and len(match.group()) == 10:
		print('YES')
	else:
		print('NO')


import re
NUM = re.compile('^[789]\\d{9}$')
for _ in range(int(input())):
	print('YES' if NUM.match(input()) else 'NO')


import re
num = int(input())
for i in range(num):
	number = input()
	if len(number) != 10:
		print('NO')
	else:
		match = re.search('[7,8,9]\\d\\d\\d\\d\\d\\d\\d\\d\\d', number)
		if match:
			print('YES')
		else:
			print('NO')


import re
numbers = int(input())
for numbercounter in range(numbers):
	number = input()
	if len(number) != 10:
		print('NO')
		continue
	temp = re.match('^[789][0-9]{9}', number)
	if temp:
		print('YES')
	else:
		print('NO')


import re
for i in range(int(input())):
	s = str(input())
	print('YES' if re.match('^[789]{1}[0-9]{9}$', s) else 'NO')


import fileinput
import re
input()
for line in fileinput.input():
	if re.search('^[987][0-9]{9}$', line):
		print('YES')
	else:
		print('NO')


import re

def valid(phone):
	reg = re.compile('^[789][0-9]{9}$')
	return reg.match(phone)
n = int(input())
for i in range(0, n):
	phone = input()
	if valid(phone):
		print('YES')
	else:
		print('NO')


import sys
import re
n = int(sys.stdin.readline().strip())
numbers = []
for x in range(n):
	num = sys.stdin.readline().strip()
	valid = bool(re.search('^[7-9]{1}[0-9]{9}$', num))
	numbers.append([num, 'YES' if valid else 'NO'])
[print(x[1]) for x in numbers]


import re
n = int(input())
for i in range(n):
	a = input()
	if re.search('[7-9]{1}[0-9]{9}', a) and len(a) == 10:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	inp = input()
	for c in inp:
		if c not in '9876543210':
			print('NO')
			break
	else:
		if len(inp) == 10 and inp[0] in '987':
			print('YES')
		else:
			print('NO')


import sys
import re

def freopen(f, option, stream):
	import os
	oldf = open(f, option)
	oldfd = oldf.fileno()
	newfd = stream.fileno()
	os.close(newfd)
	os.dup2(oldfd, newfd)
n = int(input())
for i in range(n):
	str = input()
	match = re.search('[789][\\d]*', str)
	if match:
		ans = match.group()
		if len(ans) == 10:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


N = int(input())
while N > 0:
	n = input()
	if (n[0] is '7' or n[0] is '8' or n[0] is '9') and len(n) is 10 and (n.isnumeric() == True):
		print('YES')
	else:
		print('NO')
	N = N - 1


import re
for num in [input() for i in range(int(input()))]:
	if re.search('^[789][0-9]{9}$', num):
		print('YES')
	else:
		print('NO')


import re
n = int(input())
for i in range(n):
	print('YES' if re.match('^[789]\\d{9}$', input()) else 'NO')


import re
for line in (input() for i in range(int(input()))):
	if re.match('^[789][0-9]{9}$', line):
		print('YES')
	else:
		print('NO')


import re
N = int(input())
pattern = re.compile('^[7-9][0-9]{9}$')
while N > 0:
	print('YES' if re.match(pattern, input().strip()) else 'NO')
	N -= 1


import re
t = int(input())
pattern = '^(7|8|9)(\\d{9})$'
while t > 0:
	t -= 1
	number = input()
	if re.search(pattern, number):
		print('YES')
	else:
		print('NO')


import re
num = input()
validityArray = {}
for i in range(int(num)):
	number = input()
	validity = re.search('^[7|8|9]([0-9]+)$', number)
	if validity != None and len(number) == 10:
		validityArray[i] = 'YES'
	else:
		validityArray[i] = 'NO'
for i in range(len(validityArray)):
	print(validityArray[i])


import re
i = int(input())
for j in range(0, i):
	x = input()
	y = re.search('([0-9]+)', x)
	z = re.search('(^[7-9]+)', x)
	if y and z:
		if len(x) == 10 and y.group(1) == x:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import re
n = int(input())
p = re.compile('^[789]\\d{9}$')
for i in range(n):
	s = input()
	print('YES' if p.match(s) else 'NO')


import re
for _ in range(int(input())):
	print('YES' if re.match('^[789]\\d{9}$', input()) else 'NO')


n = int(input())
for i in range(0, n):
	tmp_str = input()
	len_tmp_str = len(tmp_str)
	if len_tmp_str != 10:
		print('NO')
	elif tmp_str[0] != '7' and tmp_str[0] != '8' and (tmp_str[0] != '9'):
		print('NO')
	else:
		check = 1
		for i in tmp_str:
			if i >= '0' and i <= '9':
				continue
			else:
				check = 0
				break
		if check == 1:
			print('YES')
		else:
			print('NO')


import re
size = int(input())
for i in range(size):
	num = input()
	match = re.search('^[7-9]\\d{9}$', num)
	if match:
		print('YES')
	else:
		print('NO')


import sys, re
num = int(input())
for i in range(0, num):
	phone = input()
	if re.search('^[789]\\d\\d\\d\\d\\d\\d\\d\\d\\d$', phone):
		print('YES')
	else:
		print('NO')


numTrials = int(input())
phlist = []
for i in range(numTrials):
	s = input()
	phlist.append(s)
for j in phlist:
	if len(j) == 10 and (j[0] == '7' or j[0] == '8' or j[0] == '9') and j.isnumeric():
		print('YES')
	else:
		print('NO')


import re
pat = re.compile('^[789]\\d{9}$')
n = int(input())
for i in range(n):
	line = input()
	if pat.match(line):
		print('YES')
	else:
		print('NO')


import re
phone = re.compile('[7-9]\\d{9}$')
for i in range(int(input())):
	print('YES' if phone.match(input()) else 'NO')


n = int(input())
import re
pattern = re.compile('^[789]\\d{9}$')
for _ in range(n):
	number = input()
	print('YES' if pattern.match(number) else 'NO')


import re
n = int(input())
for i in range(n):
	print('YES' if re.match('^[789][0-9]{9}$', input()) else 'NO')


def is_number(s):
	try:
		float(s)
		return True
	except ValueError:
		return False
for n in range(int(input())):
	x = input()
	if is_number(x) and len(x) == 10 and (x[0] == '7' or x[0] == '8' or x[0] == '9'):
		print('YES')
	else:
		print('NO')


import re
cases = int(input())
for i in range(0, cases):
	string = input()
	match = re.search('[789][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]', string)
	if match and len(string) == 10:
		print('YES')
	else:
		print('NO')


it = int(input())
for i in range(it):
	k = input()
	if k.isnumeric() and len(k) == 10 and (k[0] >= '7'):
		print('YES')
	else:
		print('NO')


import re
N = int(input())
while N > 0:
	NN = input()
	match = re.search('[7-9]{1}\\d{9}', NN)
	if match and len(NN) == 10:
		print('YES')
	else:
		print('NO')
	N -= 1


j = input()
n = int(j)
for i in range(0, n):
	b = input()
	p = 0
	try:
		c = int(b)
		length = 0
	except:
		print('NO')
		p = 1
	finally:
		if p == 0:
			while int(c / 10) != 0:
				length += 1
				c = c / 10
			length += 1
			k = int(c)
			if length != 10:
				print('NO')
			elif k == 9 or k == 8 or k == 7:
				print('YES')
			else:
				print('NO')


import re

def get_input():
	lines = []
	num_lines = int(input())
	for i in range(num_lines):
		lines.append(str(input()).strip())
	return lines

def check_num(line):
	if re.match('^[789]\\d{9}$', line):
		print('YES')
	else:
		print('NO')

def main():
	lines = get_input()
	for line in lines:
		check_num(line)
main()


import re
for i in range(int(input())):
	phone_pat = '^[7-9]\\d{9}$'
	if re.match(phone_pat, input()):
		print('YES')
	else:
		print('NO')


import re
n = int(input())
i = 0
while i < n:
	num = input()
	exp = re.search('(^[7-9])([0-9]{9}$)', num)
	if exp:
		print('YES')
	else:
		print('NO')
	i += 1


import re
t = int(input())
for i in range(0, t):
	z = input()
	if len(z) == 10:
		if re.search('^[789]\\d+$', z) != None:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import re
for _ in range(int(input())):
	m = re.match('^[789]\\d{9}$', input())
	print('YES' if m else 'NO')


import sys
import re
numberre = re.compile('[789]\\d{9}$')
(_, numbers) = (input(), sys.stdin.read().split())
for number in numbers:
	if numberre.match(number):
		print('YES')
	else:
		print('NO')


import sys
import re
for x in range(int(sys.stdin.readline())):
	str = sys.stdin.readline()
	if len(str.strip()) != 10:
		print('NO')
		continue
	if re.match('[7,8,9][0-9]{9}', str):
		print('YES')
	else:
		print('NO')


tt = input()
tt = int(tt.rstrip())
while tt > 0:
	n = input()
	n.rstrip()
	check = True
	if len(n) != 10:
		print('NO')
	elif n[:1] == '7' or n[:1] == '8' or n[:1] == '9':
		for i in n:
			if ord(i) < 48 or ord(i) > 57:
				check = False
		if check:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	tt = tt - 1


from sys import stdin
from re import fullmatch, compile
valid_number = compile('[7-9]{1}\\d{1,14}$')
valid = lambda s: len(s) == 10 and fullmatch(valid_number, s)

def main():
	num_test_cases = int(stdin.readline())
	for i in range(num_test_cases):
		print('{:s}'.format('YES' if valid(stdin.readline().rstrip()) else 'NO'))
main()


t = int(input())
for i in range(t):
	temp = input()
	if temp.isdigit() and len(temp) == 10 and (temp[0] == '7' or temp[0] == '8' or temp[0] == '9'):
		print('YES')
	else:
		print('NO')


import re
r = re.compile('^[7-9][0-9]{9}$')
n = int(input())
for i in range(n):
	num = input()
	if r.match(num):
		print('YES')
	else:
		print('NO')