- Posts: 14
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Regular expression to set a minimum number of words/characters
- fmerken
- Topic Author
- Offline
- New Member
Less
More
3 years 5 months ago #208824
by fmerken
Regular expression to set a minimum number of words/characters was created by fmerken
I need to set a minimum number of characters or words in my questionnaire. I have chosen a long text box, and I have set the maximum number of characters to 1800, and I would like to set the minimum to 1000 characters (or the minimum to 200 words and the maximum to 300 words).
I used several regular expressions, but I don't know where to type them (conditional filter equation, or question validation equation). I tried :
{ ^[-\w]+(?:\W+[-\w]+){199,200}\W*$} --> syntax not recognized by LimeSurvey
{strlen(this) > 1000} --> seems not to work even if syntax is recognized
{^.{200,}$} --> syntax not recognized
I'm stuck at this point. Could someone explain to me where exactly I should enter the regular expression, and which one is the right one to limit the number of characters or words?
Thank you
I used several regular expressions, but I don't know where to type them (conditional filter equation, or question validation equation). I tried :
{ ^[-\w]+(?:\W+[-\w]+){199,200}\W*$} --> syntax not recognized by LimeSurvey
{strlen(this) > 1000} --> seems not to work even if syntax is recognized
{^.{200,}$} --> syntax not recognized
I'm stuck at this point. Could someone explain to me where exactly I should enter the regular expression, and which one is the right one to limit the number of characters or words?
Thank you
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10118
- Thank you received: 3598
3 years 5 months ago - 3 years 5 months ago #208829
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Regular expression to set a minimum number of words/characters
If using a regular expression in the "Question validation equation" field, you need to use the regexMatch() function -
manual.limesurvey.org/ExpressionScript_-...#Access_to_functions
Additionally, you do not use the curly braces in that field.
Additionally, you do not use the curly braces in that field.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 5 months ago by tpartner.
The topic has been locked.
- fmerken
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 5 months ago #208836
by fmerken
Replied by fmerken on topic Regular expression to set a minimum number of words/characters
Thank you for your answer ! Now do you know which expression would set a minimal number of characters or words? I can't find the right one.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13036
- Thank you received: 4012
3 years 5 months ago #208838
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Regular expression to set a minimum number of words/characters
This should work, if you place it in "Logic/question validation equation"
and remove the curly brackets
strlen(self) > 1000
Disadvantage: The question will show an error until you typed 1000 characters.
Joffm
and remove the curly brackets
strlen(self) > 1000
Disadvantage: The question will show an error until you typed 1000 characters.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13036
- Thank you received: 4012
3 years 5 months ago #208890
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Regular expression to set a minimum number of words/characters
You have two conditions
1. length of string ge 1000 characters
2. length of string le 2000 characters
So you have a validation equation of
strlen(Q1.NAOK) ge 1000 AND strlen(Q1.NAOK) le 2000
And in the validation tip you may create something like
{if(strlen(Q1.NAOK) lt 1000,"Please enter at least than 1000 characters",if(strlen(Q1.NAOK) gt 2000,"Please enter less than 2000 characters","That's fine"))}
Or whatever you like.
Joffm
1. length of string ge 1000 characters
2. length of string le 2000 characters
So you have a validation equation of
strlen(Q1.NAOK) ge 1000 AND strlen(Q1.NAOK) le 2000
And in the validation tip you may create something like
{if(strlen(Q1.NAOK) lt 1000,"Please enter at least than 1000 characters",if(strlen(Q1.NAOK) gt 2000,"Please enter less than 2000 characters","That's fine"))}
Or whatever you like.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, fmerken
The topic has been locked.
- fmerken
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 5 months ago #208897
by fmerken
Replied by fmerken on topic Regular expression to set a minimum number of words/characters
Thanks a lot, it's been very helpful. Everything works now, except the fact that I still can't display the number of characters the participant is at. On the pictures that you posted, there's a text at the bottom of the box saying "Your text contains ... characters". How can add this?
Sorry about the double post, I'm new here and didn't know best.
Sorry about the double post, I'm new here and didn't know best.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13036
- Thank you received: 4012
3 years 5 months ago #208902
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Regular expression to set a minimum number of words/characters
Hi,
well, I put it into the help text.
But you may put it into the question text as well.
Read about it here
manual.limesurvey.org/ExpressionScript_E...e#Tailoring.2FPiping
Tayloring and piping is very important feature to create a participant friendly questionnaire.
Your text contains {strlen(self.NAOK)} characters.
Joffm
well, I put it into the help text.
But you may put it into the question text as well.
Read about it here
manual.limesurvey.org/ExpressionScript_E...e#Tailoring.2FPiping
Tayloring and piping is very important feature to create a participant friendly questionnaire.
Your text contains {strlen(self.NAOK)} characters.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- fmerken
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 5 months ago #208904
by fmerken
Replied by fmerken on topic Regular expression to set a minimum number of words/characters
Thanks you Joffm, in the help text I used :
You have entered {strlen(self.NAOK)} characters of {if(strlen(self.NAOK) lt 1000,"a minimum of 1000",if(strlen(self.NAOK) gt 2000,"a maximum of 1800","in between 1000 and 1800 characters"))}
It all seems to work now.
Best regards
You have entered {strlen(self.NAOK)} characters of {if(strlen(self.NAOK) lt 1000,"a minimum of 1000",if(strlen(self.NAOK) gt 2000,"a maximum of 1800","in between 1000 and 1800 characters"))}
It all seems to work now.
Best regards
The topic has been locked.