- 8

I want to print phone number validator program

import re def isValid(s): # 1) Begins with 1,8 or 9 # 2) Then contains 7 or 8 or 9. # 3) Then contains 8 digits Pattern = re.compile("(1/8-9)?[8-9][0-9]{8}") return Pattern.match(s) # Driver Code s = "347873923408" if (isValid(s)): print ("Valid") else : print ("Invalid") #3/5 cases are correct

27th Oct 2020, 6:15 PM
Prerna Vijay Lohar.
Prerna Vijay Lohar. - avatar
25 Respostas
+ 35
import re #your code goes here num = str(input()) pattern = "\A(1|8|9)\d{7}
quot; if re.match(pattern,num): print("Valid") else: print("Invalid") #I got my answer
2nd Nov 2020, 3:54 PM
Prerna Vijay Lohar.
Prerna Vijay Lohar. - avatar
+ 6
import re #your code goes here num = str(input()) length = len(num) pattern = r"^(1|8|9)" if re.match(pattern,num) and length == 8: print("Valid") else: print("Invalid") # You can also do like this
17th Oct 2021, 7:18 AM
GURURAJ KL
GURURAJ KL - avatar
+ 1
Pattern = re.compile("[1|8|9][7-9][0-9]{8}") '/' is a charecter there '|' is works as or So hope it works.
27th Oct 2020, 10:39 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
import re #your code goes here num = str(input()) pattern = "\A(1|8|9)\d{7}
quot; if re.match(pattern,num): print("Valid") else: print("Invalid") #answer
13th Mar 2021, 6:38 PM
Maruf Ashurov
Maruf Ashurov - avatar
+ 1
import re #your code goes here num = str(input()) pattern = "\A(1|8|9)\d{7}
quot; if re.match(pattern,num): print("Valid") else: print("Invalid")
24th Apr 2021, 4:08 PM
Faramarz Kowsari
Faramarz Kowsari - avatar
+ 1
mport re #your code goes here pattern = "\A(1|8|9)\d{7}
quot; num_input = str(input()) match = re.match(pattern, num_input) if match: print("Valid") else: print("Invalid")
6th Dec 2021, 5:21 PM
miki
miki - avatar
+ 1
import re #your code goes here number = input() pattern = r"[189]" if re.match(pattern, number) and len(number)==8: print("Valid") else: print("Invalid")
10th Jul 2022, 4:11 PM
Abhishek Chaudhary
Abhishek Chaudhary - avatar
+ 1
import re #your code goes here num = input() pattern = r'^[1|8|9]' match = re.findall(pattern,num) if match and len(num)==8: print("Valid") else: print("Invalid")
19th Oct 2022, 12:06 PM
Ali Aamir
Ali Aamir - avatar
+ 1
import re #your code goes here number = input() pattern = r"(1|8|9)\d{7}
quot; if re.search(pattern,number): print("Valid") else: print("Invalid")
27th Nov 2022, 8:58 AM
Pareshkumar Chaudhari
0
Nooo it doesn't work
28th Oct 2020, 5:06 PM
Prerna Vijay Lohar.
Prerna Vijay Lohar. - avatar
0
which one not working for which case can you say it clearly...?
28th Oct 2020, 9:27 PM
Jayakrishna šŸ‡®šŸ‡³
0
import re #your code goes here num = input() pathern = re.compile(r"^(1|8|9)(\d){7}
quot;) if pathern.search(num): print("Valid") else: print("Invalid")
2nd Apr 2021, 10:38 PM
Leider Enrique Pineda Simanca
Leider Enrique Pineda Simanca - avatar
0
import re #your code goes here num=int(input()) pattern=r"[189][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" if re.match(pattern,"num"): print('Valid') else: print('Invalid') It's not working only 3/5
28th Apr 2021, 10:49 AM
Keerthi goli
Keerthi goli - avatar
0
Building upon Prerna Vijay Lohar's answer: import re num = str(input()) pattern = "\A(1|8|9)\d{7}
quot; # \A - an anchor dictates a particular location in the search string where a match must occur. # Anchor a match to the start of <string>. # (1|8|9) - matches any 1, 8, or 9 at the start # \d{7} - \d matches any digits subsequent, {7} matches seven times (total of 8 from above) # $ indicates must end with the seven digits if re.match(pattern,num): print("Valid") else: print("Invalid")
2nd Aug 2021, 5:23 PM
iVuDang
iVuDang - avatar
0
import re pattern = "[189]\d{7}
quot; num = input() match = re.match(pattern,num) if match: print("Valid") else: print("Invalid")
5th Aug 2021, 11:57 AM
Ankush Negi
0
import re #your code goes here num = str(input()) pattern = "\A(1|8|9)\d{7}
quot; if re.match(pattern,num): print("Valid") else: print("Invalid") I got my answer with this code
25th Nov 2021, 5:17 AM
Smita Wangikar
Smita Wangikar - avatar
0
import re num = input() pathern = re.compile(r"^(1|8|9)(\d){7}
quot;) if pathern.search(num): print("Valid") else: print("Invalid")
28th Dec 2021, 10:32 AM
Md. Rakibul Islam
Md. Rakibul Islam - avatar
0
import re num = str(input()) pattern = r"\A(1|8|9)\d{7}
quot; if re.match(pattern,num): print("Valid") else: print("Invalid") can't be better than this
31st May 2022, 10:53 AM
MATHEW Desmond Oyeyemi
MATHEW Desmond Oyeyemi - avatar
0
import re #your code goes here num = str(input()) pattern = "\A(1/8/9)\d{7}
quot; if re.match(pattern,num): print("Valid") else: print("Invalid")
13th Jul 2022, 1:17 PM
Sobana priyal . T
0
import re def valid(s): pattern = re.compile("^[189]\d{7}
quot;) return pattern.match(s) s = input("") if (valid(s)): print("Valid") else: print("Invalid") THIS IS THE CORRECT ONE
12th Nov 2022, 6:44 PM
Draghici Radu