How to prevent 0 as the first character? | XM Community
Skip to main content

Hi,
In my survey I have a question where participants have to enter a number. I would like to prevent 0 as the first character. Is there a way to do it using javascript?
Thanks.

Hi there, if you still need, I was able to put this in place on a Text Entry question by adding the below to the OnReady of the question's JavaScript:
jQuery("#"+this.questionId+" input[type=text]").on("input",function() {

this.value = this.value.replace(/[^0-9]*/g,'');

var text = this.value;
var lefttext = text.charAt(0);

if(lefttext=='0') {
  jQuery(this).val(null);
}

});


Leave a Reply