validation numerical question

More
5 years 7 months ago #76686 by dragraham
dragraham created the topic: validation numerical question
LimeSurvey newbie here...

We are asking a question in numerical format for which we want to constrain possible responses to 0-365. Is there a way to do this in the validation field? I have read online documentation and am still not sure how to proceed. If someone could paste a quick line of code for this, it would be much appreciated!

Thanks in advance!

Please Log in to join the conversation.

More
5 years 7 months ago #76688 by Ben_V
Ben_V replied the topic: validation numerical question
you can try:

/^([0-9]|[0-9][0-9]|[0-3][0-6][0-5]|)$/

Ben-

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in to join the conversation.

More
5 years 7 months ago #76689 by TMSWhite
TMSWhite replied the topic: validation numerical question
An better way is to use the advanced question settings.

Set "Minimum Value" to 0 and "Maximum Value" to 365.

Documentation is available here:
(1) single numerical input
(2) multiple numerical input

Please Log in to join the conversation.

More
5 years 7 months ago - 5 years 7 months ago #76695 by Ben_V
Ben_V replied the topic: validation numerical question
OUPS..! I was wrong...better with this format !
/^([0-9]|[0-9][0-9]|1[0-9][0-9]||2[0-9][0-9]||3[0-5][0-9]|36[0-5])$/

Or you can use a javascript alert (adapting qID variable)
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// adapt qID
var qID = 123;
var msg = 'Wrong...must be <366';
$('#question'+qID+' input.text').change(function(){
if($(this).val() && ($(this).val() > 365)) {
alert (msg);
$(this).val('');
}
});
});
</script>

Set "Minimum Value" to 0 and "Maximum Value" to 365.

since 1.91...not present in previous version :(

Ben

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last Edit: 5 years 7 months ago by Ben_V.
The following user(s) said Thank You: dragraham

Please Log in to join the conversation.

More
5 years 7 months ago #76696 by dragraham
dragraham replied the topic: validation numerical question
Thanks Ben - it works!! Thanks for the speedy reply!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now