Mobile app custom input validation

Mobile app custom input validation

  

Hi,

In our mobile app we have a input field that we want to only allow positive integers.

What is the best way to do it?

I've tried to run client action 'onChange' and 'onKeyup' and 'onBlur' but it doesn't work 100% of the times. The best effect was if we run action 'onBlur' of input and if the value is not a number instead of 0 set it to 1. Is there something I'm missing or how it is better to set value to 0 on 'on-fly' field validation?

Thank you.

Hello Mykola

Do you mean you don't even want to allow users to input a negative number? If you change the InputType to Number, the user won't be able to type the "-" to make it a negative number. You can add custom validations in the save action to prevent the app from saving negative values too.

Otherwise I don't know any means to prevent the user from even typing undesired values


Regards,

Ângelo

Hello Ângelo,

Running custom validation is not a problem by itself. Actually the problem is that if the value of the variable is set to 0 during the client action (because it is not a number for example) it doesn't set input value to 0 as I would expect but just leaves it as is. If I set value to 1 for example instead of 0 it is working. This makes me think there is some kind of bug in the prices that syncs variable value and displayed input value (that assumes 0 is not a new value) or I'm using it incorrectly. 


Hello Mykola

But if you set the input type to number, then the user won't be able to type anything that's not a number, correct?

Regards,

Ângelo

In Chrome user can type 'e' and in Safari any text. Any difference that input type makes is that when the cursor is in it user can use up and down arrow to increase/decrease value by 1.