Use regex and/or java script to validate a list (long free text).

More
1 month 1 day ago #174052 by PeteReffell
PeteReffell created the topic: Use regex and/or java script to validate a list (long free text).
We use LimeSurvey to collect monitoring data from a range of third sector/charitable organisations. The data is centred around a large number of projects, some of which will deliver services to many people and some of which to only a few.

For most of the data collection this is not a problem as we only want numbers as integers, e.g., How many participants have gone on to form friendships..., and then a number is entered.

But for postcodes we want to know how many people use a service by UK postcode area, for which we use the first part of the UK postcode - LS11, WF3, etc. and the first number of the second part, this is then followed by the number of participants from that area accessing the service, eg.:
LS11 5, 6
WF3 2, 2

To avoid a ridiculous number of subquestions, it is better that we validate a list (long free text), which then provides us with a csv.
Ideally we would also like to display the total to assist those completing the survey. As many of the projects are delivered by very small community organisations some respondents will be entering directly into the answer whilst others will copy and paste from their own spreadsheets, we want to make sure that the number of participants' postcode areas inputted is equal to the total number of participants they have worked with. We want to make it easy for people to return data to us, and running totals is a great way to help people.
Previously we asked for an excel file/csv, however, it appears that different people have wildly different ideas as to what might constitute a spreadsheet file, attachment, upload, etc.
I appreciate that this is not a trivial task and any help or pointers would be greatly appreciated. I'm not very familiar with regex - the basics, but I'm on a steep learning curve.
Thanks
Pete

Please Log in or Create an account to join the conversation.

More
4 weeks 1 day ago #174208 by PeteReffell
PeteReffell replied the topic: Use regex and/or java script to validate a list (long free text).
I'm keeping it simple and using regex to validate the answer text:

/^[a-z]{2}[0-9]{1,2}\s[0-9][,\t]\s?[0-9]{1,2}$/im

which identifies the first instance of the postcode and then takes the answer as validated. I can get it to validate a fixed number of lines, but the number of lines that will be added isn't fixed.
Any help? It just needs to validate the list in the long free text.
I've attached an example in a survey.
Many thanks
Attachments:

Please Log in or Create an account to join the conversation.

More
4 weeks 10 hours ago #174345 by PeteReffell
PeteReffell replied the topic: Use regex and/or java script to validate a list (long free text).
I know I'm probably missing something really obvious and I've tried to use
var mystring = new RegExp(^[a-z]{2}[0-9]{1,2}\\s[0-9][,\\t]\\s?[0-9]{1,2}$)
to iterate through the answer in JS, but I'm modifying a script designed to look for unwanted words and expression and I'm not even sure it runs in 3.x
I'll stop asking after this, as it now feels a little awkward, but it's worth a last ask for assistance.
Thanks
Pete

Please Log in or Create an account to join the conversation.

More
4 weeks 5 hours ago #174354 by holch
holch replied the topic: Use regex and/or java script to validate a list (long free text).
I am not sure if regex allows to iterate through lines. You might need to move from line to line via Javascript. But I am not an expert o this.

As this forum is mainly run by volunteers, sometimes it happens that questions are unaswered, either because no one had an answer or because the people who would be able to answer are currently on holiday, very busy at work or just overlooked your question.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
3 weeks 6 days ago #174369 by PeteReffell
PeteReffell replied the topic: Use regex and/or java script to validate a list (long free text).
Thanks,
It's something that I thought would be straightforward, but turns out not to be - or not for me. I guess I hoped there would be some some magic regex bullet I had missed. I appreciate that people are volunteers.
I'm kind of resigned to javascript now so it's just hobbling it together.
Pete

Please Log in or Create an account to join the conversation.

More
3 weeks 5 days ago #174386 by holch
holch replied the topic: Use regex and/or java script to validate a list (long free text).
I am by no means a REGEX expert and there might be solutiosn over various lines...

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!