How to check if character has been restricted in a TextInput?

107 views Asked by At

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.

2

There are 2 answers

0
user1875642 On BEST ANSWER

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.

0
Brian On

There's no SDK method to check the incoming char. You'll have to query the restrict text (ideally on the changing event).