0
Some of the test cases are not running(phone number validator), why?
import re number = input() pattern=r"(1|8|9)[0-9]+" match=re.match(pattern,number) if len(number)==8: if(match): print("valid") else: print("Invalid")
5 Answers
+ 3
Emerson Prado ,
if you take moment and check the code that shifa has posted, you can see that there is one issue concerning the length of the phone number. i posted this detail. this is NOT a finished code.
additionally i gave i gave a hint about using the findall() function...
so i can not agree with your post - sorry!
+ 2
shifa
If len is not 8 then what should print?
There is 'Valid' not 'valid'
+ 2
shifa ,
we can improve the regex pattern so that it also can match for the length of the complete string:
pattern = "^(1|8|9)[0-9]{7}quot;
^ => match has to start at the beginning of the string
$ => match has to end at the end of the string
{7} => defines the length of the second character group
i would also recommend to use:
match = re.findall(...,...)
+ 1
Lothar I saw this issue. Your explanations on multipliers and anchors are good. I just think you could leave out the finished regexp, for the OP to build it.
0
Lothar , pls do not give finished code as answer, for the reasons exaustively explained