Skip to content

Commit b9826f6

Browse files
authored
Merge pull request #30 from HighnessAtharva/patch-10
Update Validatingphonenumbers.py
2 parents 8e764a7 + 3c17ef1 commit b9826f6

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

RegexandParsing/Validatingphonenumbers.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,17 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 3 April 2021
78
Problem : https://www.hackerrank.com/challenges/validating-the-phone-number/problem
89
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
n=int(raw_input())
11-
for i in range(0,n):
12-
tmp_str=raw_input()
13-
len_tmp_str=len(tmp_str)
14-
if(len_tmp_str!=10):
15-
##print "LENGTH PROBLEM"
16-
print "NO"
17-
elif(tmp_str[0]!="7" and tmp_str[0]!="8" and tmp_str[0]!="9"):
18-
##print "START PROBLEM"
19-
print "NO"
10+
11+
from re import compile, match
12+
13+
n = int(input())
14+
for _ in range(n):
15+
phone_number = input()
16+
condition = compile(r'^[7-9]\d{9}$')
17+
if bool(match(condition, phone_number)):
18+
print("YES")
2019
else:
21-
check=1
22-
for i in tmp_str:
23-
if(i>="0" and i<="9"):
24-
continue
25-
else:
26-
check=0
27-
break
28-
if(check==1):
29-
print "YES"
30-
else:
31-
##print "NUMBER PROBLEM"
32-
print "NO"
20+
print("NO")

0 commit comments

Comments
 (0)