How to remove extra spaces and characters in a column of data?

Howdy Ya’ll!

I have a column with phone numbers formatted like this: '+1 816-537-5108. How do I remove the extra characters and spaces and leave just the numbers?

1 Like

Howdy @Chris_Scott !

If you added another column with the formula filter(str.isdigit, $Phone), that could work.

Or a trigger formula of filter(str.isdigit, str(value)) could clean up phone numbers as you enter them.

2 Likes

@paul-grist Thanks for that! Not I’m doing something incorrectly but I can’t figure out what…

Try this recipe: create a new column, put into it the formula:

"".join(c for c in $First_Phone if c.isdigit())

Make sure it’s a formula column (as opposed to a data column).

The approach with str.isdigit looked right to me, but when I tried it, I got the error 'isdigit' requires a 'str' object but received a 'unicode':

This recipe would work too if you replaced str with unicode. The difference between str and unicode is an unfortunate complexity of Python in dealing with text, but it will get better with our planned Python upgrade. Luckily, it does not affect the recipe above.

2 Likes

Thanks @dmitry-grist and @paul-grist that last one got it!.

1 Like