Premium problem155. Strip Phone Numbers to Digits

Medium Locked

contacts has columns contact_id and phone, entered with spaces, parentheses, plus signs and hyphens in every combination. Some are missing.

Add a digits column holding only the digits of each number, and a valid boolean that is True when the result has between 10 and 15 digits inclusive. A missing phone yields a missing digits and valid False. Return the original columns plus the two new ones, index unchanged.

Input

   contact_id              phone
0           1  +1 (415) 555-0100
1           2      020 7946 0958
2           3              12345
3           4               None

Output

   contact_id              phone       digits  valid
0           1  +1 (415) 555-0100  14155550100   True
1           2      020 7946 0958  02079460958   True
2           3              12345        12345  False
3           4               None         None  False

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)