Setting a Max Character Count for a Field

A user wrote into support asking how to set a maximum number of characters in a field. This is possible with a formula and access rule. I wanted to share the example more widely in case it’s useful to others.

Example doc: Limit Character Count - Grist

There is a short video on the right-hand side that you can watch that explains what I am about to explain here.

  1. The Max 20 Characters column is the column in which I would like to limit entries to a max of 20 characters.
  2. The Over 20 character? column is a formula column that is counting the number of characters in the Max 20 Characters column. If the character count is above 20, the formula returns True, which is what we will prevent using access rules. The formula is len($Max_20_Characters) > 20
  3. In access rules, I created a rule for this table to prevent the new record created after either an update or record creation from toggling the Over 20 character? column to True. The rule is newRec.Over_20_character_ == True and I denied Update [U] and Create [C] permissions.

The newRec variable is available for record/row creation and updating, and contains the state of a row after a proposed change, allowing you to selectively allow or deny certain changes.

In the video, you can see me test this rule with the text in the 21 characters column, which has exactly 21 characters. You can test this yourself by saving a copy of this example document.

There is another option to silently truncate a field to 20 characters:

As a trigger formular (data cleaning):

return value[0:20]

1 Like

Ooh, that is a great tip, too! I added it to my example.