You are viewing a single comment's thread. Return to all comments →
import re phone_numbers = [input() for i in range(int(input()))] pattern = r'^[789]\d{9}$'
for phone_number in phone_numbers: match = re.match(pattern, phone_number) print("YES" if bool(match) else "NO")
for i in [input() for i in range(int(input()))]: print("NO" if not i.isnumeric() or int(i[0])<7 or len(i)!=10. else "YES")
Seems like cookies are disabled on this browser, please enable them to open this website
Validating phone numbers
You are viewing a single comment's thread. Return to all comments →
with regex
import re phone_numbers = [input() for i in range(int(input()))] pattern = r'^[789]\d{9}$'
for phone_number in phone_numbers: match = re.match(pattern, phone_number) print("YES" if bool(match) else "NO")
without regex
for i in [input() for i in range(int(input()))]: print("NO" if not i.isnumeric() or int(i[0])<7 or len(i)!=10. else "YES")