Prevent Characters

Mehr
4 Monate 2 Wochen her #169443 von waitz
waitz erstellte das Thema 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her - 4 Monate 2 Wochen her #169446 von Joffm
Joffm antwortete auf das Thema: 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
Letzte Änderung: 4 Monate 2 Wochen her von Joffm.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her #169447 von waitz
waitz antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her - 4 Monate 2 Wochen her #169450 von Joffm
Joffm antwortete auf das Thema: 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
Letzte Änderung: 4 Monate 2 Wochen her von Joffm.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her #169451 von waitz
waitz antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her #169461 von Joffm
Joffm antwortete auf das Thema: 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
Anhang:
Folgende Benutzer bedankten sich: tpartner, waitz

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her #169466 von waitz
waitz antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 2 Wochen her #169474 von waitz
waitz antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha