TextField: limit allowed characters?
Is it possible to limit user input in a textfield? For example, I'd like to allow only numbers in a particular field.
2 Answers
-
Accepted Answer
I have this on the change event, to restrict the input to numbers and under a certain limit
customer_phone_limit = 10;
the change event triggers this function
function(e) { var val = phone.value; !!( /[^0-9]/.test(val) ) ? phone.value = val.replace(/[^0-9]/gi,'') ): false ; e.source.value = e.source.value.slice(0,customer_phone_limit); }
-
if you are only wanting numbers in a textfield, then you should just bring up the number keyboard instead of the regular keyboard. that way there's no way for someone to type in anything other than numbers.
rocksteady,
danno~