How to ensure that negative number can't be entered for text entry? | XM Community
Skip to main content
Solved

How to ensure that negative number can't be entered for text entry?

  • April 29, 2020
  • 5 replies
  • 723 views

Forum|alt.badge.img

I saw on this thread how to ensure that only numbers can be entered for text entry:
How to set a field to number only?I specifically used this solution to make it so respondents can only enter integers between 0 and 9:
jQuery("#"+this.questionId+" .InputText").attr({'type':'number','min':'0', 'max':'9'});
However, I've noticed that a minus sign can still be entered (e.g., "- 5"). Is there some way to prevent this possibility?

Best answer by rondev

Check this post

5 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • April 29, 2020

No need of custom code here, as this feature is present in qualtrics. In text entry question, select validation type as "Content validation", content type as "Number" and under numeric format put 0 as min and 9 as max


Forum|alt.badge.img+2
  • Level 2 ●●
  • April 29, 2020

how about using "pattern":"[0-9]{1}"?
: The Input (Form Input) element


Forum|alt.badge.img
  • Author
  • April 29, 2020

How to ensure that negative number can't be entered for text entry?This doesn't quite work because this problem is embedded within a trickier problem where I want to display 6 entry forms side-by-side for text entry. This code gets be very close except for being able enter minus signs:

Qualtrics.SurveyEngine.addOnReady(function()

{

/*Place your JavaScript here to run when the page is fully displayed*/



var that = this.questionId;

  jQuery("#"+this.questionId+" td:not(.ControlContainer)").hide();

jQuery("#"+this.questionId+" .InputText").css("max-width","2em");

jQuery("#"+this.questionId+" .InputText").attr("maxlength", "1");

  jQuery("$").insertBefore(jQuery("#"+that+" .InputText:eq(0)"));

  jQuery("#"+that+" .InputText:eq(1)").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));

jQuery("#"+that+" .InputText:eq(2)").insertAfter(jQuery("#"+that+" .InputText:eq(1)"));

jQuery("#"+that+" .InputText:eq(3)").insertAfter(jQuery("#"+that+" .InputText:eq(2)"));

jQuery("#"+that+" .InputText:eq(4)").insertAfter(jQuery("#"+that+" .InputText:eq(3)"));

jQuery("#"+that+" .InputText:eq(5)").insertAfter(jQuery("#"+that+" .InputText:eq(4)"));

  jQuery(",").insertAfter(jQuery("#"+that+" .InputText:eq(2)"));

jQuery("#"+this.questionId+" .InputText").attr({'type':'number','min':'0', 'max':'9'});



Forum|alt.badge.img
  • Author
  • April 29, 2020

How to ensure that negative number can't be entered for text entry?This didn't work either. I tried this code and was able to input letters etc.
jQuery("#"+this.questionId+" .InputText").attr({"pattern":"[0-9]{1}"});


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • April 29, 2020

Check this post