0

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

In course "Python Core" Code project 91 - Phone Number Validator 2 variants of code behaves strangely at https://www.sololearn.com/learning/eom-project/1073/356 1 variant 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") --------------------------------------------------------- and 2 variant --------------------------------------------------------- import re #your code goes here pattern = r"[189]\d{7}

quot; 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, 4:48 PM
Dmitry Arkhangelsky
4 Réponses
0
It's "1" or "8" or "9": [1|8|9]
16th Aug 2021, 5:38 PM
Simon Sauter
Simon Sauter - avatar
0
Thanks for your wise advice Simon, sorry for stupid mistake
16th Aug 2021, 5:57 PM
Dmitry Arkhangelsky
0
There's nothing stupid about this. It takes time to memorise these things.
16th Aug 2021, 6:00 PM
Simon Sauter
Simon Sauter - avatar
0
import re num = input () pattern = r"^[1|8|9][0-9]*
quot; if re.match(pattern,num) and len(num)==8: print("Valid") else: print("Invalid")
19th Nov 2021, 3:06 PM
Stefan Bartl
Stefan Bartl - avatar