Finding valid phone number
Problem to find the valid phone number.
The valid phone number is
- The length should be 10.
- All the character are numbers only.
- The number start from 6 or 7 or 8 or 9
Example-1:
Input : n = "9876543210,8976543210,6578994,798790,7986543210,6987543210" Output : ['9876543210', '8976543210', '7986543210','6987543210']
Example-2:
Input : n = "9#5@6*7&4$,7c8r9a6z5y,8976543210" Output : ['8976543210']
Solution
s = "9876543210,8976543210,6578994,798790,7986543210,5987543210" result = re.findall(r"[6-7-8-9]{1}[0-9]{9}",s) print(result)
Output
['9876543210', '8976543210', '7986543210']