Prevent Characters

More
4 months 2 weeks ago #169443 by waitz
waitz created the topic: Prevent Characters
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?

Version 2.73.1+171220

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago - 4 months 2 weeks ago #169446 by Joffm
Joffm replied the 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


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last Edit: 4 months 2 weeks ago by Joffm.

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #169447 by waitz
waitz replied the 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?

Version 2.73.1+171220

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago - 4 months 2 weeks ago #169450 by Joffm
Joffm replied the topic: Prevent Characters
Hi, waitz,
wrong syntax.
You have to enter:
regexMatch('[Regular expression code',self)

for "self" read:
https://manual.limesurvey.org/Expression_Manager#The_reserved_.27this.27.2C_.27self.27.2C_and_.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: 4 months 2 weeks ago by Joffm.

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #169451 by waitz
waitz replied the 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:
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

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #169461 by Joffm
Joffm replied the 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


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: tpartner, waitz

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #169466 by waitz
waitz replied the 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?

Version 2.73.1+171220

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #169474 by waitz
waitz replied the 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 :-)

Version 2.73.1+171220

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!