- 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
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
+ 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
+ 1
Pattern = re.compile("[1|8|9][7-9][0-9]{8}")
'/' is a charecter there
'|' is works as or
So hope it works.
+ 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
+ 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")
+ 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")
+ 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")
+ 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")
+ 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")
0
Nooo it doesn't work
0
which one not working for which case can you say it clearly...?
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")
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
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")
0
import re
pattern = "[189]\d{7}quot;
num = input()
match = re.match(pattern,num)
if match:
print("Valid")
else:
print("Invalid")
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
0
import re
num = input()
pathern = re.compile(r"^(1|8|9)(\d){7}quot;)
if pathern.search(num):
print("Valid")
else:
print("Invalid")
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
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")
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