Objective
Create a Python program that validates mobile phone numbers with a pattern that includes an optional part.
Instructions
- Read an integer
nand thennphone numbers, one per line. - A phone number is valid if it has an optional prefix
+34(with the space) followed by 9 digits, the first of which is a 6 or a 7. The pattern isr"(\+34 )?[67]\d{8}". - Use
re.fullmatch. - Show
ValidorNot validfor each phone number.
4
600123456
+34 700123456
500123456
+34600123456
Valid
Valid
Not valid
Not valid
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise