Welcome to the LimeSurvey Community Forum

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

How to set up postcode validation for multiple languages?

  • alorenc
  • alorenc's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 5 months ago #210668 by alorenc
I want to set up the validation of a postcode field in a question. I have added a few languages but I can see that this field is common to all of them. Where the postcode differs from country.

Can it be done at all?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #210672 by Joffm
Try to combine the language and the validation of postcode in your question validation.
The language is stored in the variable {LANG},

Something like
(LANG=='de' AND regexMatch('/^\d{5}$/',self)) OR (LANG=='nl' AND regexMatch('/^\d{4}[A-Z]{2}$/',self)) OR ...
And for the validation tip there are all languages available.

But maybe it is better not to make it dependent on the language, but from the country.
So instaed of "LANG=='en'" something like "Q1==1", if "1" was the code of the country in question "Q1".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 5 months ago by Joffm.
The following user(s) said Thank You: alorenc
The topic has been locked.
  • alorenc
  • alorenc's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 5 months ago #210679 by alorenc
I was surprised that in the table "Questions" it creates a new row when adding the language version, but the column "preg" is common to both, e.t. other attributes from the core (main category)

But now he understands that it is actually better to use "em_validation_q" instead of "preg" for this as I can define error messages.

In fact, it would be better to add a country to the form if the fields are to be validated against the country.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 5 months ago #210689 by DenisChenu

alorenc wrote: In fact, it would be better to add a country to the form if the fields are to be validated against the country.

No,

Because a large majority of usage are : same condition for all language but tips different for each language.

If you different confdition for each language :
  1. More complex for a large majority of user
  2. More complex for developper (mean more bug)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The following user(s) said Thank You: alorenc
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #210696 by holch
I don't think adding a country column makes sense. The next one comes and wants a "organization" column and the next one, and the next one.

Already the various languages can make things quite complicated.

So either you write your validation accordingly considering the country (which can be quite different from language, just like Joffm mentioned) or you use copies of the survey for each country, which sometimes might actually the best and cleanest way to do it.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The following user(s) said Thank You: alorenc
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose