- 1
Whats wrong with this code i keep getting a wrong answer on the phonenumber validator challange import re #your code goes here
Pythoncore
4 Réponses
+ 1
Hello Mkhuliseni Sithole
Please show us your code.
+ 1
import re
#your code goes here
num = input()
pattern = r"[1,8,9][0-9]{7}"
matCh = re.search(pattern,num)
if matCh:
print ("Valid")
else:
print("Invalid")
Dnt know if its visible to you
+ 1
Mkhuliseni Sithole
The number need to start with 1, 8, or 9
to check the first character you need ^
"^a" would match every string which starts with a
() is for a group
| means or
^(1|8|9)
starts with 1 or 8 or 9
Now you only need to make sure that your number has 8 digits (not more not less)
https://www.programiz.com/JUMP_LINK__&&__python__&&__JUMP_LINK-programming/regex
+ 1
Danke Maneer( Thank you very much) Denise