+ 2
Phone number validator
I was able to pass the challenge with this code, but when I test it the code is flawed. I can start with any number and get valid. https://code.sololearn.com/cX5xUa0DxB2r/?ref=app
6 odpowiedzi
+ 8
Can you share a specific test case that isn't behaving correctly?
"1234abcd" starts with a number and is invalid and the code correctly indicates "Invalid".
"12345678" prints "Valid" which is probably what you want.
This is the code I saw when I clicked your link in case you update it:
import re
num = input()
pattern = r"^{^1|8|9}|{^1-9}"
if re.search(pattern, num) and len(num) == 8:
print("Valid")
else:
print("Invalid")
+ 3
import re
number = input()
pattern = r"[189][0-9]{7}\Z"
matches = re.match(pattern, number)
if matches:
print("Valid")
else:
print('Invalid')
This works Well
+ 2
I’ve now fixed the code
pattern = r"^[1|8|9][0-9]{7}quot;
0
This one got me through.
import re
number = input()
pattern = r"[189]\d{7}quot;
if re.match(pattern, number):
print("Valid")
else:
print("Invalid")
0
import re
num = input()
pattern = r"^[1|8|9].{7}"
if re.match(pattern, num) and len(num) == 8:
print("Valid")
else:
print("Invalid")
this one was nice and compact
- 2
68963279 this prints valid