How to validate input in a text field ?
Hi,
I'm creating an application with some text field which are supposed to contain only floating point numbers. How can I prevent the user from typing too many characters in such field ?
In typical web apps, one would register for the key press event and stop unwanted events. I don't see a similar mechanism in Appcelerator.
Thanks.
2 Answers
-
I do it like this:
the_input.addEvent('change', function(e){ e.source.value = e.source.value.slice(0,the_limit); } );
it will allow you to enter only what the_limit allows ( let's say 10 )
-
I have written a validator library for my app which takes a lot free form data. Due to the type of data and form design I cat the data a the end and present a alert dialogue with information on the problems.
I might change this in future and check on change event firing.