+ 1

What is error in "phone Number validation ". it failed 4th case.

import re def isValid(s): # 1) Begins with 1 or 8 or 9 # 2) Then contains 8 digits Pattern = re.compile(r"^(1/8/9)?[8]") return Pattern.match(s) # Code s = input() if (isValid(s)): print ("Valid") else : print ("Invalid")

30th Oct 2020, 1:35 PM
Abhishek Yadav
Abhishek Yadav - avatar
3 Answers
+ 2
Maybe repeat the chapter to understand the syntax. Use [] for sets of characters and {} for quantification (also ? + *)
30th Oct 2020, 2:42 PM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
+ 1
Starts with 1, 8 or 9: ^[189] Contains 8 digits (=7 more) : [0-9]{7} Then it should end: $
30th Oct 2020, 2:45 PM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
0
There will be needed the end with 8 digits. You can first test your code on the Playground and see what happend. This can be done with printing of few variables. https://code.sololearn.com/cx1tfbykB3pp/?ref=app
30th Oct 2020, 1:59 PM
JaScript
JaScript - avatar