Welcome to the LimeSurvey Community Forum

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

Use Regex to avoid user to fill in non english/ non US keyboard for text field

  • bennetyu
  • bennetyu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 4 months ago #101336 by bennetyu
I need to setup a question set by not allowing user to fill in non english character in the free text field.

I tried different regular expressions but all not work fine in validation. Is it possible to use the field validation feature or any work around to limit user to fill in english character only?
The topic has been locked.
  • bennetyu
  • bennetyu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 4 months ago #101350 by bennetyu
It should works with below RegEx.

/^[\x20-\x7E]*$/
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 4 months ago #101359 by tpartner
I don't understand. Are you trying to limit the input to any character from uppercase A to lowercase z with no punctuation allowed?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • bennetyu
  • bennetyu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 4 months ago #101376 by bennetyu
Hi Tony,

I have a free text question only allow participant to answer in English only.

As i am expect some participants will type in their answer in Chinese, Japanese or other asian languages, I need to validate before submission and that's why i want to know if any regEx in the validator can serve this purpose. theor workaround can identify user is typing in US keyboard characters.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 4 months ago - 10 years 4 months ago #101386 by tpartner
Try this for the "Question validation equation" - it should restrict to the unicode block range for basic Latin characters:
Code:
regexMatch('/^[\u0000-\u007F]*$/', this)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 4 months ago by tpartner.
The topic has been locked.
  • bennetyu
  • bennetyu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 4 months ago #101422 by bennetyu
Hi Tony,

Thanks for your help. When i do the test for this validation, there is something strength happened with below steps.

1. I go to webpage to paste chinese content to the free text box, the textbox turns red and alert user the content is not Latin character.
2. i removed all the content in the textbox, the textbox resume to white color.
3. Paste pure English content into the same text box, the text box turns red again.

It seems that it only happens when there is copy and paste. If the content is typing in, it won't turns red.

I am using Limesurvey version 2.0, Is it a mirror bug happens on error checking in the limesurvey?

Thanks,
Bennet
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 4 months ago #101427 by tpartner
Sorry, I cannot reproduce that problem.

Typing or pasting Latin characters passes the validation (white input).

Pasting in Chinese characters fails the validation (pink input).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • bennetyu
  • bennetyu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 4 months ago #101435 by bennetyu
Hi Tony,

It should be reverse the steps. You paste chinese text to make it pink and delete it. Then paste the english text with more than 6 lines (do not type), it will turns red again.

Thanks,
Bennet
The topic has been locked.
  • bennetyu
  • bennetyu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 4 months ago #101686 by bennetyu
I found out the problem and it was due to a copied the English content from a webpage and it is encoded by UTF-8characters indeed. So even it is an English characters but not in ASCII encoding.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose