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

How to prevent 0 as the first character?

  • March 22, 2021
  • 1 reply
  • 331 views

Forum|alt.badge.img+1

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.

1 reply

Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • October 27, 2022

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);
}

});