-
Notifications
You must be signed in to change notification settings - Fork 8
/
Validating_phone_numbers.py
52 lines (34 loc) · 1.14 KB
/
Validating_phone_numbers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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
# or
# .
# Concept
# A valid mobile number is a ten digit number starting with a
# or
# .
# 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
# , the number of inputs.
# lines follow, each containing some string.
# Constraints
# 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
import re
N = int(input())
for i in range(N):
a = raw_input()
l = len(a)
matchObj = re.search("^[789][0-9]{9}$", a)
if matchObj:
print "YES"
else:
print "NO"