- Posts: 56
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
validation of multiple numeric inputs
- AntPIC
- Topic Author
- Offline
- Senior Member
Less
More
2 weeks 12 hours ago #260548
by AntPIC
validation of multiple numeric inputs was created by AntPIC
Versione 3.28.76Hi, I'm looking for an expression for validating a multiple entry numeric response (attached).
The response is validated if:
1. both boxes are empty;
2. if at least one of the two is full with a maximum length of 4 numeric digits
These two work
But I would need to enter a third option:
3. i.e. if both are filled in then the first value inserted must be lower than the second.
Here is the expression I am using (the bold part works but the second one doesn't)(is_empty(D1a3_SQ001.NAOK) OR strlen(D1a3_SQ001.NAOK) == 4) AND (is_empty(D1a3_SQ002.NAOK) OR strlen(D1a3_SQ002.NAOK) == 4) OR (!is_empty(D1a3_SQ001.NAOK) AND !is_empty(D1a3_SQ002.NAOK) AND D1a3_SQ002>=D1a3_SQ001)how can I solve it
The response is validated if:
1. both boxes are empty;
2. if at least one of the two is full with a maximum length of 4 numeric digits
These two work
But I would need to enter a third option:
3. i.e. if both are filled in then the first value inserted must be lower than the second.
Here is the expression I am using (the bold part works but the second one doesn't)(is_empty(D1a3_SQ001.NAOK) OR strlen(D1a3_SQ001.NAOK) == 4) AND (is_empty(D1a3_SQ002.NAOK) OR strlen(D1a3_SQ002.NAOK) == 4) OR (!is_empty(D1a3_SQ001.NAOK) AND !is_empty(D1a3_SQ002.NAOK) AND D1a3_SQ002>=D1a3_SQ001)how can I solve it
Attachments:
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12994
- Thank you received: 3996
1 week 6 days ago #260595
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic validation of multiple numeric inputs
Hi,
To achieve that sett the validation to
count(self)<2 or (count(self)==2 and Q1_SQ001<=Q1_SQ002)
with a validation tip like
{if(count(self)==2 and Q1_SQ001>Q1_SQ002,"Conclusione greater or equal sottoscrizione","")}
Furthermore you may force the four digits and at the same time a certain range of years by a regular expression like
/^(([1][9][5-9][0-9])|([2][0][01][0-9])|([2][0][2][0-4]))?$/
Here from 1950 - 2024
Joffm
To achieve that sett the validation to
count(self)<2 or (count(self)==2 and Q1_SQ001<=Q1_SQ002)
with a validation tip like
{if(count(self)==2 and Q1_SQ001>Q1_SQ002,"Conclusione greater or equal sottoscrizione","")}
Furthermore you may force the four digits and at the same time a certain range of years by a regular expression like
/^(([1][9][5-9][0-9])|([2][0][01][0-9])|([2][0][2][0-4]))?$/
Here from 1950 - 2024
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- AntPIC
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 56
- Thank you received: 0
1 week 5 days ago #260682
by AntPIC
Replied by AntPIC on topic validation of multiple numeric inputs
Thank you Joffm,
This work
count(self)<2 or (count(self)==2 AND D1a3_SQ001.NAOK<=D1a3_SQ002.NAOK)
Can I add a limit to the string of numbers which must be equal to 4?
This work
count(self)<2 or (count(self)==2 AND D1a3_SQ001.NAOK<=D1a3_SQ002.NAOK)
Can I add a limit to the string of numbers which must be equal to 4?
Please Log in to join the conversation.
- AntPIC
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 56
- Thank you received: 0
1 week 5 days ago #260688
by AntPIC
Replied by AntPIC on topic validation of multiple numeric inputs
I just put this
/^([1-9][0-9][0-9][0-9])?$/
is correct?
/^([1-9][0-9][0-9][0-9])?$/
is correct?
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12994
- Thank you received: 3996
1 week 5 days ago #260690
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic validation of multiple numeric inputs
It is correct syntax, but it allows
1492
8745
Not very realistic years
1492
8745
Not very realistic years
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- AntPIC
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 56
- Thank you received: 0
1 week 5 days ago #260691
by AntPIC
Replied by AntPIC on topic validation of multiple numeric inputs
and if i want a range between 1900-2100? What i have to insert?
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12994
- Thank you received: 3996
1 week 5 days ago #260774
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic validation of multiple numeric inputs
You see what I entered to limit from 1950 to 2024.
And you may use
[url] regex101.com/ [/url]
to get more familiar with regular expressiona.
And you may use
[url] regex101.com/ [/url]
to get more familiar with regular expressiona.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- AntPIC
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 56
- Thank you received: 0
1 week 5 days ago #260787
by AntPIC
Replied by AntPIC on topic validation of multiple numeric inputs
Thanks Joffm
/^(195[0-9]|19[6-9][0-9]|20[0-9]{2}|2100)$/
/^(195[0-9]|19[6-9][0-9]|20[0-9]{2}|2100)$/
Please Log in to join the conversation.