Restricting special characters | XM Community
Solved

Restricting special characters

  • 30 October 2020
  • 6 replies
  • 44 views

Badge +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

icon

Best answer by TomG 30 October 2020, 16:53

View original

6 replies

Userlevel 7
Badge +27

Use .replace() with regex.

Badge +1

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

Can you please to share the full code?

Thanks in Advance.

Userlevel 7
Badge +27

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

Badge +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

Userlevel 7
Badge +27

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

Badge +1

Thanks a lot . This worked.

Leave a Reply