- 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"
6 Réponses
+ 1
I'm not a snobb, thanks
+ 1
Sorry Thomas, I'll try once more
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!
0
With my total respect Calvin Thomas, the site rposeeds Your elegant code with the same error
0
Dmitry Arkhangelsky I just tested my code here. It works just fine.
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")