Python Regex | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python Regex

Phone Number Validation Fails on test case 4 only couldn’t figure out. import re #your code goes here number = input('') pattern = r'[981]\d{7}' for num in number: matches = re.match(pattern, number) if matches: print('Valid') else: print('Invalid')

13th Dec 2020, 10:33 PM
Muhammad Yaqoob
Muhammad Yaqoob - avatar
2 Answers
+ 1
try starting the pattern with the starting character symbol: ^ and ending with the end character symbol: $ r"^[981]\d{7}
quot;
14th Dec 2020, 1:45 AM
Slick
Slick - avatar
0
you must check for the length too
14th Dec 2020, 1:45 AM
madeline
madeline - avatar