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

andy_dandy_d Salt Lake City, UT, USACommunity Member - Trial User Qubie ✭

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

I saw on this thread how to ensure that only numbers can be entered for text entry:

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?

Tagged:

Best Answer

Answers

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭

    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

  • TJUH_KaiTJUH_Kai Philadelphia, PACommunity Member Guru ✭✭
  • andy_dandy_d Salt Lake City, UT, USACommunity Member - Trial User Qubie ✭
    edited April 29

    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("<span>$</span>").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("<b>,</b>").insertAfter(jQuery("#"+that+" .InputText:eq(2)"));
    
    	jQuery("#"+this.questionId+" .InputText").attr({'type':'number','min':'0', 'max':'9'});
    
    


  • andy_dandy_d Salt Lake City, UT, USACommunity Member - Trial User Qubie ✭

    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}"});
    
Sign In to Comment