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

More
3 years 7 months ago #101336 by bennetyu
bennetyu created the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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?

Please Log in to join the conversation.

More
3 years 7 months ago #101350 by bennetyu
bennetyu replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
It should works with below RegEx.

/^[\x20-\x7E]*$/

Please Log in to join the conversation.

More
3 years 7 months ago #101359 by tpartner
tpartner replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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.

Please Log in to join the conversation.

More
3 years 7 months ago #101376 by bennetyu
bennetyu replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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.

Please Log in to join the conversation.

More
3 years 7 months ago - 3 years 7 months ago #101386 by tpartner
tpartner replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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.
Last Edit: 3 years 7 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 7 months ago #101422 by bennetyu
bennetyu replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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

Please Log in to join the conversation.

More
3 years 7 months ago #101427 by tpartner
tpartner replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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.

Please Log in to join the conversation.

More
3 years 7 months ago #101435 by bennetyu
bennetyu replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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

Please Log in to join the conversation.

More
3 years 7 months ago #101686 by bennetyu
bennetyu replied the topic: Use Regex to avoid user to fill in non english/ non US keyboard for text field
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.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now