Welcome, Guest
Username: Password: Remember me

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

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 3 weeks ago #101336

  • bennetyu
  • bennetyu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101350

  • bennetyu
  • bennetyu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
It should works with below RegEx.

/^[\x20-\x7E]*$/
The administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101359

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4281
  • Thank you received: 807
  • Karma: 370
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101376

  • bennetyu
  • bennetyu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101386

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4281
  • Thank you received: 807
  • Karma: 370
Try this for the "Question validation equation" - it should restrict to the unicode block range for basic Latin characters:
regexMatch('/^[\u0000-\u007F]*$/', this)
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 11 months 2 weeks ago by tpartner.
The administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101422

  • bennetyu
  • bennetyu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101427

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4281
  • Thank you received: 807
  • Karma: 370
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 2 weeks ago #101435

  • bennetyu
  • bennetyu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.

Use Regex to avoid user to fill in non english/ non US keyboard for text field 11 months 6 days ago #101686

  • bennetyu
  • bennetyu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.162 seconds
Donation Image