Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Word Count

  • jltrussart11
  • jltrussart11's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162199 by jltrussart11
Word Count was created by jltrussart11
Hello,


I'm trying to use the EM to count words.


This one works.

{if(regexMatch('/^[-\w]+(?:\W+[-\w]+){1,10}\W*$/', Titrefinal), join("Excellent, you have less than ",NbMaxMotTitre," words."), join("You have too much words. You must have a maximum of ",NbMaxMotTitre," words."))}

But I can't parse a calculated field.

{if(regexMatch('/^[-\w]+(?:\W+[-\w]+){1,NbMaxMotTitre.NAOK}\W*$/', Titrefinal), join("Excellent, you have less than ",NbMaxMotTitre," words."), join("You have too much words. You must have a maximum of ",NbMaxMotTitre," words."))}

Any idea?

Thanks in advance!
The topic has been locked.
More
6 years 2 months ago #162204 by davebostockgmail
Replied by davebostockgmail on topic Word Count
I have come across this in the past so I hope this helps ...

If you need to enter a minimum amount of words then this works .... replace [QID] with your question ID.

regexMatch('/^[-\w]+(?:\W+[-\w]+){4,1000}\W*$/', [QID])

{if([QID] != '' && !regexMatch('/^[-\w]+(?:\W+[-\w]+){4,9}\W*$/', [QID]), 'Please enter more than 5 words.', '')}

If you need to warn on a minimum number of words but allow the user to move on if they want to, then this has worked for me as an entry in the source view of the question.

<script>
$(document).ready(function() {

var confirmShown = 0;
// Interrupt the submit process
$('#movenextbtn, #movesubmitbtn').bind('click', function () {
if($("#answerSIDXGIDXQID").val().length < 4 && confirmShown == 0) {
confirmShown = 1;
var moveOn = confirm("Your feedback is important to us; Are you sure that there is no detail you would like to share? \n\nIf you would like to add anything more, please click 'Cancel' to add to your answer.\n\nIf you have nothing else to add, please click 'OK' to proceed to the next question");
if (moveOn == false) {
return false;
}
}
});

});
</script>
The following user(s) said Thank You: jltrussart11, cmnxyz
The topic has been locked.
  • jltrussart11
  • jltrussart11's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162213 by jltrussart11
Replied by jltrussart11 on topic Word Count
Thanks, for your precious help!

I'll try to be more specific. I'm trying to manage the word limit in an other question.

Q1 (WordLimit) : What is the limit of word that your title can contains
Q2 (Title): Type your title.

Tips of Q2: "Your title respect the limit of words" or "Your title exceed the word limit."


From you example, I've try this, but it's doesnt works.

{if('' && !regexMatch('/w/', Title.NAOK) <= WordLimit.NAOK ,"Your title respect the limit of words","Your title exceed the word limit.")}

Any idea?

Thanks again!
The topic has been locked.
More
4 years 11 months ago #183329 by cmnxyz
Replied by cmnxyz on topic Word Count
Hey Dave,

can you tell me where to put those 2 expressions?

regexMatch('/^[-\w]+(?:\W+[-\w]+){4,1000}\W*$/', [QID])

{if([QID] != '' && !regexMatch('/^[-\w]+(?:\W+[-\w]+){4,9}\W*$/', [QID]), 'Please enter more than 5 words.', '')}

Just started to work with LimeSurvey and a bit overwhelmed.

Kind regards

Franz
The topic has been locked.
More
4 years 11 months ago #183363 by davebostockgmail
Replied by davebostockgmail on topic Word Count
That goes in the question validation equation ....

regexMatch('/^[-\w]+(?:\W+[-\w]+){4,1000}\W*$/', [QID])

And this in the question validation tip ....

{if([QID] != '' && !regexMatch('/^[-\w]+(?:\W+[-\w]+){4,9}\W*$/', [QID]), 'Please enter more than 5 words.', '')}
The following user(s) said Thank You: DenisChenu
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose