- 1

Whats wrong with this code i keep getting a wrong answer on the phonenumber validator challange import re #your code goes here

Pythoncore

19th Jan 2022, 5:22 PM
Mkhuliseni Sithole
4 ответов
+ 1
Hello Mkhuliseni Sithole Please show us your code.
19th Jan 2022, 5:49 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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
19th Jan 2022, 6:20 PM
Mkhuliseni Sithole
+ 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
19th Jan 2022, 6:43 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Danke Maneer( Thank you very much) Denise
19th Jan 2022, 6:46 PM
Mkhuliseni Sithole