Restricting special characters | XM Community
Skip to main content
Solved

Restricting special characters

  • October 30, 2020
  • 6 replies
  • 118 views

Forum|alt.badge.img+1

Hi Experts,

In one of my Survey question i need to validate the participants should enter only 8 numbers. I have achieved using the below jquery code.
And now i also want to restrict special characters. Please help how to achieve this,
Below code used to restrict only 8 numbers.
jQuery("#"+this.questionId+" .InputText").each(function () { 
  jQuery(this).on("input", function() { this.value = this.value.substr(0,8); });

Thanks in Advance,
Krishna Prabhu

Best answer by TomG

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

6 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 30, 2020

Use .replace() with regex.


Forum|alt.badge.img+1

Thanks for replying. But i am not getting entire code.

Can you please to share the full code?

Thanks in Advance.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 30, 2020

You weren't specific enough about what you want to exclude.


Forum|alt.badge.img+1

Hi Tom,

I want to exclude Characters and special characters. The participants have to enter only numbers of length 8. Please help.
I am new to Qualtrics with limited knowledge in coding.
Thanks in advance,
Krishna Prabhu


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • October 30, 2020

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


Forum|alt.badge.img+1

Thanks a lot . This worked.