Intro

This article explains how to manage leading and treading whitespace (blanks) when copying and pasting text into input controls (such as input fields, text areas, and so on).

Typically, whitespaces are not typed manually, but rather appear as a byproduct of copying and pasting content into the input control.

Whitespace can have negative impact to further processing. For example:

  • Fields might not be found in an exact search for the visible string.
  • It could lead to cluttered text alignment.
  • System(s) might distinguish objects “ABC” from “˽ABC” and “ABC˽”, which are visually equal to the user.
  • Fields with a fixed string length could risk losing data. For example, an input field with a maximum string length of 10 might receive “˽1234567890” via copying and pasting, but only be able to save “˽123456789” due to length limitations.

In order to avoid such issues, leading and trailing blanks can be automatically removed or trimmed.

Usage

Leading blanks within product IDs
Leading blanks within product IDs

Use field trimming if:

  • The leading or trailing whitespace is not needed for the business process.
  • The input fields have uniquely identifying business objects.
  • The input fields have a fixed field length.

Do not use field trimming if:

  • The use case explicitly requires leading/trailing whitespace. For example, for formatted text such as chats, comments, descriptions, source code, or for file names (according to the supported OS behavior).
  • For text areas where users would expect leading whitespace as a formatting tool.

Guidelines

The system behavior for field trimming should be coherent in all editing applications of a field and in all external interfaces (for example, for importing, system integration, and so on).