Start page / Template development / Rules / Form properties <PROPERTY/> / Property LENGTH

LENGTH property

Checking the number of characters of an input component

Some FirstSpirit input components provide length information on their saved values; for example:

With the aid of this information, a template developer can evaluate the number of characters that an editor enters in an input component using rules. In addition to the limitation of a maximum number of characters, a limitation of a required minimum number of characters or even a check for the equal number of characters can be carried out using a dynamic form. These comparisons can be checked against a numeric constant, for example (“No more than 1024 characters can be entered”), or against a variable comparison value (e.g. the length information of an additional input component).

The expression <PROPERTY source='gadget' name='LENGTH'/> can be used in the value determination area of the rule definition (or for the definition of a precondition) and returns the number of characters of the corresponding value.

To define a complete condition for length-dependent validation, there must also be a comparison value:

  • a constant, numeric comparison value (for example, <NUMBER>10</NUMBER>) or
  • a variable comparison value, such as the number characters of an additional input component

and an operator:

In this case, the expression will return a Boolean value.

Important Note: for a length check, make sure that some input components use invisible characters (for example, section markings in DOM). This should be taken into account when creating the rule. If, for example, the input component is a type CMS_INPUT_DOM input component, then the editor can enter fewer than the defined 1,024 characters in the example shown below, because every invisible section marking also counts as a character.


Example 1) Simple length check for an input component:

The following form contains a “cs_description” input component (of type CMS_INPUT_DOM) for entry of a product description. A dynamic form is used to ensure that the input of the editor does not exceed a certain number of characters.

In addition, within the <WITH/> section, the number of characters of the input component is retrieved and compared against a numerical constant. The result of this “Greater than” check is a Boolean value which is also linked with a validation of the input component in the <DO/> section. As long as the condition (“Number of characters is not greater than 1024”) is not fulfilled, the <VALIDATION/> section of the rule is run and a correction notice appears. Through the SAVE attribute, saving the form is also prevented.

<PROPERTY source="cs_description" name="LENGTH"/>
<PROPERTY source="cs_description" name="VALID"/>
<MESSAGE lang="*" text="Only 1,024 characters allowed!"/>
<MESSAGE lang="DE" text="Es sind nur 1.024 Zeichen zugelassen!"/>

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.5 | Data privacy