Question T7771
Visible to All Users

Single input: allow only integer numbers

created 3 years ago (modified 3 years ago)

Is there a way to only allow integers in a Single input with "inputType": "number"? It always allows to enter float values like 3.2. I assumed that the step value = 1 would prevent the input of floats, but it does not do the job.

Code
{     "type""text",     "name""q1", "inputType": "number", "step": 1 }

I've tried to work around it with a regex validation, like the following. But the validation does not fire on an float input?!

Code
{     "type""text",     "name""q1",     "validators": [         {             "type""regex",             "text""Validation 1 fired",             "regex""[0-9]*"         }     ] }

Can someone help me on that? I would expect that to be easy.

Answers approved by surveyjs Support

created 3 years ago

Hello,

I think that we could improve the regex and it will work as expected:

JavaScript
"regex": "^[0-9]*$"

here the example: https://plnkr.co/edit/Zt040AcZ74GCQVEv

Thank you,
Dmitry
SurveyJS Team