|
| 1 | +# 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. |
| 2 | + |
| 3 | +# A valid mobile number is a ten digit number starting with a |
| 4 | +# or |
| 5 | + |
| 6 | +# . |
| 7 | + |
| 8 | +# Concept |
| 9 | + |
| 10 | +# A valid mobile number is a ten digit number starting with a |
| 11 | +# or |
| 12 | + |
| 13 | +# . |
| 14 | + |
| 15 | +# 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. |
| 16 | + |
| 17 | +# https://developers.google.com/edu/python/regular-expressions |
| 18 | + |
| 19 | +# Input Format |
| 20 | + |
| 21 | +# The first line contains an integer |
| 22 | +# , the number of inputs. |
| 23 | + |
| 24 | +# lines follow, each containing some string. |
| 25 | + |
| 26 | +# Constraints |
| 27 | + |
| 28 | +# Output Format |
| 29 | + |
| 30 | +# 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. |
| 31 | + |
| 32 | +# Sample Input |
| 33 | + |
| 34 | +# 2 |
| 35 | +# 9587456281 |
| 36 | +# 1252478965 |
| 37 | + |
| 38 | +# Sample Output |
| 39 | + |
| 40 | +# YES |
| 41 | +# NO |
| 42 | + |
| 43 | +import re |
| 44 | +N = int(input()) |
| 45 | +for i in range(N): |
| 46 | + a = raw_input() |
| 47 | + l = len(a) |
| 48 | + matchObj = re.search("^[789][0-9]{9}$", a) |
| 49 | + if matchObj: |
| 50 | + print "YES" |
| 51 | + else: |
| 52 | + print "NO" |
0 commit comments