Is there a function to remove trailing spaces + double spaces?

Topic Labels: Formulas
1845 3
Showing results for 
Search instead for 
Did you mean: 
6 - Interface Innovator
6 - Interface Innovator

Basically, if a field has an extra space at the beginning or end from human error, I want to automatically remove it. Also, is there a way to flag a field that has extra spaces? Some kind of data validation when adding to the field?

3 Replies 3

Hey @Chris_Dukes!

You could accomplish this a few ways.

The simplest way to do so would be to create a formula field that utilizes the TRIM() function.
This function will remove any trailing whitespace in text strings.

The next step-up in complexity would be an automation.

Depending on how many automation runs you have, you can set the trigger however you’d want.
For the action, you’d want to take the value(s) in the text field and have the update action utilize the trim text transformation to append the value into the field.

The cleanest, but most complex method I can come up with is to utilize a script automation.
The String.trim method would knock this out easily.

Then you can just append the validated data to the field.

If people will be typing directly in the field, I don’t recommend using an automation. The automation might trigger while the person is typing.

However, if the values will come in complete via a form submission or the API, you can have an automation that removes trailing spaces. You don’t even need to have a formula field in some cases. Have an “On Form Submission” trigger. Then update the record with the trimmed field name. In the “Update Record” action, when you select a field value, instead of directly inserting the field value, click “continue” and pick the “trim” option.

Try this formula field.

  LEN({field}) != LEN(TRIM({field})),
  "Field has extra spaces"