0
Please help me i don't know why this doesn't work. i think group 1 in varnumpattern doesn't work properly
""" You are given a number input, and need to check if it is a valid phone number. A valid phone number has exactly 8 digits and starts with 1, 8 or 9. Output "Valid" if the number is valid and "Invalid", if it is not. """ import re possiblevnum = input() vnumpattern = r"(1|8|9)(\d.......)?" num_matching = re.match(vnumpattern, possiblevnum) """ the reason i added isinstance is because if i didn't, after the first number, you could input letters along with numbers that would still count as valid """ if num_matching and isinstance(possiblevnum, int): print('Valid') else: print('Invalid')
5 Answers
+ 2
vnumpattern = r"[189]\d{7}quot;
if num_matching:
+ 1
try it now
0
i am not sure why, but it worked for all of them except test case 3. i cannot view what the input is so i don't know. thank you for the response though.
0
nvm i found out what the problem was
0
Yeah what you edited was the solution I found as well. Thanks for the help. Your original response helped me find the correct answer still.