- Posts: 36
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Prevent Characters
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
5 years 9 months ago #169443
by waitz
Version 2.73.1+171220
Prevent Characters was created by waitz
Is there a way to prevent a user to enter a quotation mark in text fields?
And if so, what kind of error message would he get?
And if so, what kind of error message would he get?
Version 2.73.1+171220
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12791
- Thank you received: 3941
5 years 9 months ago - 5 years 9 months ago #169446
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Prevent Characters
Hi,
my first idea is:
Set a question validation with a regular expression.
Here you enter your individual error message.
Kind regards
Joffm
my first idea is:
Set a question validation with a regular expression.
Here you enter your individual error message.
Kind regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 9 months ago by Joffm.
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
5 years 9 months ago #169447
by waitz
Version 2.73.1+171220
Replied by waitz on topic Prevent Characters
Thanks Joffm
I tried entering the regex: [^"] in the Question Validation Equation, but it seems to prevent all characters:
Secondly, I see that the Question validation tip field is always showing, and I would like it only to show when someone actually enters a quotation mark.
Any tip?
I tried entering the regex: [^"] in the Question Validation Equation, but it seems to prevent all characters:
Secondly, I see that the Question validation tip field is always showing, and I would like it only to show when someone actually enters a quotation mark.
Any tip?
Version 2.73.1+171220
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12791
- Thank you received: 3941
5 years 9 months ago - 5 years 9 months ago #169450
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Prevent Characters
Hi, waitz,
wrong syntax.
You have to enter:
regexMatch('[Regular expression code',self)
for "self" read:
manual.limesurvey.org/Expression_Manager....27that.27_variables
For the showing of the tip, use the if-statement:
if(condition==true,show tip,"")
Best regards
Joffm
wrong syntax.
You have to enter:
regexMatch('[Regular expression code',self)
for "self" read:
manual.limesurvey.org/Expression_Manager....27that.27_variables
For the showing of the tip, use the if-statement:
if(condition==true,show tip,"")
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 9 months ago by Joffm.
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
5 years 9 months ago #169451
by waitz
Version 2.73.1+171220
Replied by waitz on topic Prevent Characters
Thank you. I read the link for "self". I am not a programmer though, and I just don't understand how to use it...
What I did see though was a function that strips characters, although this only at the beginning or end of a string, so it is not relevant unless there is a similar one that strips a character (") from any part of a text field:
But I am not sure if I am going in the right direction.
What I did see though was a function that strips characters, although this only at the beginning or end of a string, so it is not relevant unless there is a similar one that strips a character (") from any part of a text field:
Code:
trim: Strip whitespace (or other characters) from the beginning and end of a string string trim(string [, charlist])
But I am not sure if I am going in the right direction.
Version 2.73.1+171220
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12791
- Thank you received: 3941
5 years 9 months ago #169461
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Prevent Characters
Hi, waitz,
here is a different approach.
Use the function strpos.
Search for the character. If it is there -> false.
So enter in the question validation equation: !strpos(self,'"') (your search character, double quote, surrounded by single quotes)
Remember: This function returns false if the string is not found, otherwise the position.
So we look for the "false" result of the function.
In the tip you can enter something like:
{if(!strpos(self,'"'),"","No quotes allowed")}
Joffm
here is a different approach.
Use the function strpos.
Search for the character. If it is there -> false.
So enter in the question validation equation: !strpos(self,'"') (your search character, double quote, surrounded by single quotes)
Remember: This function returns false if the string is not found, otherwise the position.
So we look for the "false" result of the function.
In the tip you can enter something like:
{if(!strpos(self,'"'),"","No quotes allowed")}
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: tpartner, waitz
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
5 years 9 months ago #169466
by waitz
Version 2.73.1+171220
Replied by waitz on topic Prevent Characters
Thank you for describing so detailed, Joffm. I see from your screenshots that it is working, and I like the approach. I entered the same into mine, and it does not work...:
Am I doing anything fundamentally wrong?
Am I doing anything fundamentally wrong?
Version 2.73.1+171220
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
5 years 9 months ago #169474
by waitz
Version 2.73.1+171220
Replied by waitz on topic Prevent Characters
I am not sure why it was inconsistent, because it worked also. We solved it by adding a script to a hidden question at the end of the survey, replacing quotation marks with nothing: str_replace('"', "",)
Thanks
Thanks
Version 2.73.1+171220
The topic has been locked.