Welcome to the LimeSurvey Community Forum

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

Remove Spaces from Text Input

  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 8 months ago #171306 by teracomp
Remove Spaces from Text Input was created by teracomp
I have a Multiple Short Text question that includes 4 subquestions: First name, Last name, Email, and Code.

Spaces are invalid characters for email and code.

What is the best method for either disallowing spaces or removing them programmatically?

Dave Phillips
The topic has been locked.
  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 8 months ago #171309 by teracomp
Replied by teracomp on topic Remove Spaces from Text Input
I've also run into other invalid characters being entered in the email field. So the question should be broadened to "Remove Unwanted characters from Text Input"

Dave Phillips
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171311 by Joffm
Replied by Joffm on topic Remove Spaces from Text Input
Hi, teracomp,

I just tried to remove spaces programmatically.
Just by an equation like {str_replace(" ","",M1_SQ001)}. Removes one or more spaces.

Now I saw your addition.

Well here I should say, use regular expressions.

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 8 months ago #171313 by teracomp
Replied by teracomp on topic Remove Spaces from Text Input
Seems that spaces are 99% of my problem, so might be all I need.
Where do I add the equation? I've tried: {str_replace(" ","",userdata_email)} in the question "sub-question validation expression" but that does not appear to fire...at least not in the Preview Question interface.

Dave Phillips
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171319 by tpartner
Replied by tpartner on topic Remove Spaces from Text Input
If you break the question into separate short-text questions, you could use the strpos() function something like this in the question validation equation to disallow spaces.

Code:
!is_numeric(strpos(Q2, ' '))

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: teracomp
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171321 by Joffm
Replied by Joffm on topic Remove Spaces from Text Input
i set the question with the equation right after the multi text question.
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: teracomp
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171335 by DenisChenu
Replied by DenisChenu on topic Remove Spaces from Text Input

teracomp wrote: Seems that spaces are 99% of my problem, so might be all I need.
Where do I add the equation? I've tried: {str_replace(" ","",userdata_email)} in the question "sub-question validation expression" but that does not appear to fire...at least not in the Preview Question interface.

To use subquestion validation, you need something like this

str_replace(" ","",userdata_email) == userdata_email

tpartner and Joffm propose you to fix the value when user click next.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: teracomp
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose