Disabling period entry in text box | XM Community
Skip to main content
I'm trying to disable periods in the name field of a form. I've been googling for some code to update and I'm not having luck with it working. I don't want people to enter periods because it is causing problems later on in my processes.



I am trying to reference the text box in QID1, which happens to be the first form field.



Here's the code I'm trying to reuse from other sources:



Qualtrics.SurveyEngine.addOnload(function()

{

/*Place your JavaScript here to run when the page loads*/

$('QR~QID1~1~TEXT').keypress(function(key) {

if(key.charCode == 190 || key.charCode == 110) return false;

})

});



Any advice on what I can do so that the period and number pad decimal keys are disabled for this form field?



Thank you in advance!
```

jQuery("#"+this.questionId+" .InputText").on('input', function() [ this.value = this.value.replace(/\\./g, ""); });

```

Replace the [ with a { ... I had to change it to avoid the 'Access Denied' error.
@TomG this is working but it blocks periods for all of the fields in my form. I tried a few things to point it just to the first field in the form but that seemed to break it. (e.g. changing this.questionID to 'QR~QID1~1' and '#"+this.questionID+'~1'+".InputText")





My form is:

QR~QID1~1 = Name

QR~QID1~2 = Email

QR~QID~3 = Confirm email

So I need respondents to be able to put periods into their email address.





Is it possible to apply this rule to just one part of the form or should I break name and email confirmation into separate questions so the code will work?
Change .InputText to .InputText:first
Thanks @TomG! Works like a charm.

Leave a Reply