Sometimes you want Limesurvey users to enter text of a certain length at your survey. In order to provide them with some feedback about the number of characters added, you can make use of the strlen() function* of the Limesurvey Expression Manager for counting the number of characters.
* Function strlen() returns the number of bytes rather than the number of characters in a string, so special characters like ‘ or > could be counted as more than a single character.
So how can we set this up? The first step would be creating a text question at your Limesurvey survey. At most of these questions, you can already limit the number of characters the user can input:
For our test survey, we used the new Limesurvey theme “Backy” which is available at our template shop. At that theme, and most others, it looks pretty well adding the information about the number of characters directly at the help text. Since we limited the number of character to 160 we used this text for showing the number of characters to the user:
You have entered X of 160 characters.
If you want to count the number of characters of the current text question you can make use of the self variable. The code for counting the characters looks like this:{strlen(self.NAOK)}
So for the full help text we used: You have entered {strlen(self.NAOK)} of 160 characters.
If you want to show the number of characters of a different question e.g. with code textquestion you can use:
{strlen(textquestion.NAOK)}
We are using the above code to show the character count at the second text display question of our Limesurvey demo survey.
For the above test survey we are using our new shop template Backy:
Limesurvey Template Backy [Digital]
A modern Limesurvey theme with lots of theme options for customizing the template yourself.
If you need any help setting up your own character count features feel free to drop us a note any time.