- 1

In course "Python Core" Code project 91 - Phone Number Validator

In course "Python Core" Code project 91 - Phone Number Validator Code --------------------------------------------------------- import re #your code goes here pattern = r"\A[189][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\Z" if re.match(pattern, "57345672"): print ("Valid") else: print ("Invalid") --------------------------------------------------------- With Input 57345672 returns "Invalid" in IDLE (Python 3.9 64-bit) But at the site https://www.sololearn.com/learning/eom-project/1073/356 It is written that Your Output "Valid"

16th Aug 2021, 3:20 PM
Dmitry Arkhangelsky
6 Réponses
+ 1
I'm not a snobb, thanks
16th Aug 2021, 3:46 PM
Dmitry Arkhangelsky
+ 1
Sorry Thomas, I'll try once more
16th Aug 2021, 7:05 PM
Dmitry Arkhangelsky
0
Dmitry Arkhangelsky That regex makes me cringe (sorry for that). Here is a better alternative for match(): pattern = r"[189]\d{7}
quot; # Hope this helps # Happy coding!
16th Aug 2021, 3:33 PM
Calvin Thomas
Calvin Thomas - avatar
0
With my total respect Calvin Thomas, the site rposeeds Your elegant code with the same error
16th Aug 2021, 4:47 PM
Dmitry Arkhangelsky
0
Dmitry Arkhangelsky I just tested my code here. It works just fine.
16th Aug 2021, 6:05 PM
Calvin Thomas
Calvin Thomas - avatar
0
Hi Thomas! I can't understand what's wrong with the site but sololearn returns 2 errors ------------------- import re #your code goes here pattern = r"[189]\d{7}
quot; if re.match(pattern, "81234567"): print ("Valid") else: print ("Invalid")
19th Aug 2021, 2:50 PM
Dmitry Arkhangelsky