- Posts: 6
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Use regex and/or java script to validate a list (long free text).
- PeteReffell
- Topic Author
- Offline
- New Member
Less
More
5 years 7 months ago #174052
by PeteReffell
Use regex and/or java script to validate a list (long free text). was created by PeteReffell
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
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
The topic has been locked.
- PeteReffell
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
5 years 7 months ago #174208
by PeteReffell
Replied by PeteReffell on 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
/^[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:
The topic has been locked.
- PeteReffell
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
5 years 7 months ago #174345
by PeteReffell
Replied by PeteReffell on 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
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
The topic has been locked.
- holch
- Away
- LimeSurvey Community Team
Less
More
- Posts: 11655
- Thank you received: 2742
5 years 7 months ago #174354
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on 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.
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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- PeteReffell
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
5 years 7 months ago #174369
by PeteReffell
Replied by PeteReffell on 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
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
The topic has been locked.
- holch
- Away
- LimeSurvey Community Team
Less
More
- Posts: 11655
- Thank you received: 2742
5 years 7 months ago #174386
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on 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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.