Restricting characters in TextInput
can be easily done, but how can I check if particular character was restricted without manually parsing the restrict
property?
For example: restrict='a-zA-Z^L-W'
.
How do i get that B
is allowed and M
is forbidden?
If it matters, I need this functionality to show a user the explanation why his key presses don't affect the input content.
I was able to implement the message by checking input.text.indexOf(keydownchar)==-1
, but I'm interested if there's any SDK method to check the char without trying to append it into the input control.
It can be done with
StringUtil.restrict(str:String, restrict:String):String
It is exactly the method used by text display controls like RichEditableText
to handle restrict
property.
There's also more suitable method for testing single char, but unfortunately it's private:
StringUtil.testCharacter(charCode:uint, restrict:String):Boolean
Anyways it is used inside StringUtil.restrict
, so using StringUtil.restrict
instead of testCharacter
will produce the same result with performance overhead.