Given a number in form of a string s. The task is to find whether the number is valid indian mobile number or not.
Rules for valid :-indian mobile number
	The number should contain 10 or 11 or 12 digits.
	If it contains 10 digits, then first  digit should be 7 or 8 or 9.
	If it contains 11 digits, then first  digit should be 0 and second rule follwed.
	If it contains 12 digits, then first two digits should be 91 and second rule followed 
Example 1:
Input: s = "912345678999"
Output: 0
Example 2:
Input: s = "123456789"
Output: 0
 
Your Task:
You don't need to read or print anything. Your task is to complete the function is_valid() which takes s as input parameter and returns 1 if it is valid indian mobile number otherwise returns 0.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
Constraints:
1 <= |s| <= 13

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



class Solution:

	def is_valid(self, s):

		# Code here

Solutions:
import re

class Solution:

	def is_valid(self, s):
		if len(s) >= 10 and len(s) <= 12:
			if len(s) == 10:
				ans = re.search('^[7-9]', s)
				if ans:
					return 1
				else:
					return 0
			if len(s) == 11:
				ans = re.search('^0[7-9]', s)
				if ans:
					return 1
				else:
					return 0
			if len(s) == 12:
				ans = re.search('^91[7-9]', s)
				if ans:
					return 1
				else:
					return 0
		else:
			return 0


class Solution:

	def is_valid(self, s):
		if len(s) != 10 and len(s) != 11 and (len(s) != 12):
			return 0
		if len(s) == 10:
			if s[0] != '7' and s[0] != '8' and (s[0] != '9'):
				return 0
			return 1
		elif len(s) == 11:
			if s[0] != '0':
				return 0
			if s[1] != '7' and s[1] != '8' and (s[1] != '9'):
				return 0
			return 1
		else:
			if s[0] != '9' or s[1] != '1':
				return 0
			if s[2] != '7' and s[2] != '8' and (s[2] != '9'):
				return 0
			return 1


import re

class Solution:

	def is_valid(self, s):
		return 1 if re.match('^(0|91)?[789]{1}[0-9]{9}$', s) else 0


import re

class Solution:

	def is_valid(self, s):
		if not re.match('^\\d{10,12}$', s):
			return 0
		if len(s) == 10:
			if not re.match('^[789]\\d{9}$', s):
				return 0
		elif len(s) == 11:
			if not re.match('^0[789]\\d{9}$', s):
				return 0
		elif len(s) == 12:
			if not re.match('^91[789]\\d{9}$', s):
				return 0
		else:
			return 0
		return 1


import re

class Solution:

	def is_valid(self, s):
		res = re.findall('\\d', s)
		x = list(map(int, res))
		if len(x) == 10:
			if x[0] >= 7 and x[0] <= 9:
				return 1
		elif len(x) == 11:
			if x[0] == 0 and x[1] >= 7 and (x[1] <= 9):
				return 1
		elif len(x) == 12:
			if x[0] == 9 and x[1] == 1 and (x[2] >= 7) and (x[2] <= 9):
				return 1
		return 0


import re

class Solution:

	def is_valid(self, s):
		if len(s) == 10:
			if s[0] == '7' or s[0] == '8' or s[0] == '9':
				return 1
		elif len(s) == 11:
			if s[0] == '0' and (s[1] == '7' or s[1] == '8' or s[1] == '9'):
				return 1
		elif len(s) == 12:
			if s[:2] == '91' and (s[2] == '7' or s[2] == '8' or s[2] == '9'):
				return 1
		return 0


import re

class Solution:

	def is_valid(self, s):
		return 1 if re.match('(^(7|8|9)\\d{9}$)|(^0(7|8|9)\\d{9}$)|(^91(7|8|9)\\d{9}$)', s) else 0


class Solution:

	def is_valid(self, s):
		if len(s) == 10 and s[0] in '789':
			return 1
		elif len(s) == 11 and s[0] == '0' and (s[1] in '789'):
			return 1
		elif len(s) == 12 and s[:2] == '91' and (s[2] in '789'):
			return 1
		return 0


class Solution:

	def is_valid(self, s):
		n = len(s)
		ans = 0
		if n == 10:
			if s[0] == '7':
				ans = 1
			elif s[0] == '8':
				ans = 1
			elif s[0] == '9':
				ans = 1
		elif n == 11:
			if s[0] == '0':
				if s[1] == '7':
					ans = 1
				elif s[1] == '8':
					ans = 1
				elif s[1] == '9':
					ans = 1
		elif n == 12:
			if s[0:2] == '91':
				if s[2] == '7':
					ans = 1
				elif s[2] == '8':
					ans = 1
				elif s[2] == '9':
					ans = 1
		return ans


class Solution:

	def is_valid(self, s):
		s = [int(i) for i in str(s)]
		if len(s) == 10:
			if s[0] == 9 or s[0] == 8 or s[0] == 7:
				t = 1
			else:
				t = 0
		elif len(s) == 11:
			if s[0] == 0 and (s[1] == 9 or s[1] == 8 or s[1] == 7):
				t = 1
			else:
				t = 0
		elif len(s) == 12:
			if (s[0] == 9 and s[1] == 1) and (s[2] == 9 or s[2] == 8 or s[2] == 7):
				t = 1
			else:
				t = 0
		else:
			t = 0
		return t


import re

class Solution:

	def is_valid(self, s):
		if len(s) == 10:
			pattern = re.compile('^(7|8|9)')
			pat1 = pattern.match(s)
		elif len(s) == 11:
			pattern = re.compile('^0(7|8|9)')
			pat1 = pattern.match(s)
		elif len(s) == 12:
			pattern = re.compile('^91(7|8|9)')
			pat1 = pattern.match(s)
		else:
			pattern = 0
			pat1 = 0
		if pat1:
			return 1
		else:
			return 0


class Solution:

	def is_valid(self, s):
		valid = 0
		if len(s) in [10, 11, 12]:
			if len(s) == 10 and int(s[0]) in [7, 8, 9]:
				valid = 1
			elif len(s) == 11 and s[0] == '0' and (int(s[1]) in [7, 8, 9]):
				valid = 1
			elif len(s) == 12 and s[:2] == '91' and (int(s[2]) in [7, 8, 9]):
				valid = 1
		return valid


class Solution:

	def is_valid(self, s):
		l = [i for i in s]
		n = len(l)
		a = lambda i: True if l[i] == '7' or l[i] == '8' or l[i] == '9' else False
		if n == 10:
			i = 0
			return 1 if a(i) == True else 0
		elif n == 11 and l[0] == '0':
			i = 1
			return 1 if a(i) == True else 0
		elif n == 12 and l[0] == '9' and (l[1] == '1'):
			i = 2
			return 1 if a(i) == True else 0
		else:
			return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		ans = ob.is_valid(s)
		print(ans)


class Solution:

	def is_valid(self, s):
		l = len(s)
		if l != 10 and l != 11 and (l != 12):
			return 0
		else:
			if l == 11 and s[0] != '0':
				return 0
			if l == 12 and s[0:2] != '91':
				return 0
			if l == 11:
				s = s[1:]
			if l == 12:
				s = s[2:]
			if s[0] != '7' and s[0] != '8' and (s[0] != '9'):
				return 0
		return 1
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		ans = ob.is_valid(s)
		print(ans)


import re

class Solution:

	def is_valid(self, s):
		if len(s) == 10:
			out = re.search('^[7-9]\\d\\d+', s)
			if out:
				return 1
		if len(s) == 11:
			out = re.search('^0[7-9]\\d\\d+', s)
			if out:
				return 1
		if len(s) == 12:
			out = re.search('^91[7-9]\\d\\d+', s)
			if out:
				return 1
		return 0


import re

class Solution:

	def is_valid(self, s):
		pat = '91[789]\\d{9}\\b|0?[789]\\d{9}\\b'
		if re.match(pat, s):
			return 1
		return 0


class Solution:

	def is_valid(self, s):
		n = len(s)
		if n <= 9 or n > 12:
			return 0
		l = ['7', '8', '9']
		if n == 10:
			if s[0] not in l:
				return 0
		if n == 11:
			if s[0] != '0':
				return 0
			if s[1] not in l:
				return 0
		if n == 12:
			if s[0] != '9' or s[1] != '1':
				return 0
			if s[2] not in l:
				return 0
		return 1


import re

class Solution:

	def is_valid(self, s):
		n = len(s)
		if n in [10, 11, 12]:
			if n == 10:
				if re.search('^[789]', s):
					return 1
			if n == 11:
				if re.search('^0', s) and len(s[1:]) == 10 and re.search('^[789]', s[1:]):
					return 1
			if n == 12:
				if re.search('^91', s) and len(s[2:]) == 10 and re.search('^[789]', s[2:]):
					return 1
		return 0


import re

class Solution:

	def is_valid(self, s):
		l = len(s)
		p = '^(7|8|9)\\d{9}'
		if re.match(p, s) and l == 10:
			return 1
		elif re.match('0[7|8|9]\\d{9}', s) and l == 11:
			return 1
		elif re.match('91(7|8|9)\\d{9}', s) and l == 12:
			return 1
		else:
			return 0