Welcome, Guest
Username: Password: Remember me

TOPIC: validation numerical question

validation numerical question 2 years 7 months ago #76686

  • dragraham
  • dragraham's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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!
The administrator has disabled public write access.

Re: validation numerical question 2 years 7 months ago #76688

  • Ben_V
  • Ben_V's Avatar
  • NOW ONLINE
  • Platinum Lime
  • Posts: 1119
  • Thank you received: 253
  • Karma: 78
you can try:

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

Ben-
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Re: validation numerical question 2 years 7 months ago #76689

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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
The administrator has disabled public write access.

Re: validation numerical question 2 years 7 months ago #76695

  • Ben_V
  • Ben_V's Avatar
  • NOW ONLINE
  • Platinum Lime
  • Posts: 1119
  • Thank you received: 253
  • Karma: 78
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

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 2 years 7 months ago by Ben_V.
The administrator has disabled public write access.
The following user(s) said Thank You: dragraham

Re: validation numerical question 2 years 7 months ago #76696

  • dragraham
  • dragraham's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
Thanks Ben - it works!! Thanks for the speedy reply!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.165 seconds
Donation Image