简体   繁体   English

如何检查TextInput中的字符是否受到限制?

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

Restricting characters in TextInput can be easily done, but how can I check if particular character was restricted without manually parsing the restrict property? 可以很容易地完成TextInput字符限制,但是如何在不手动解析restrict属性的情况下检查特定字符是否受到restrict

For example: restrict='a-zA-Z^L-W' . 例如: restrict='a-zA-Z^L-W' How do i get that B is allowed and M is forbidden? 我如何获得允许B和禁止M的信息?

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. 我能够通过检查input.text.indexOf(keydownchar)==-1来实现消息,但是我很感兴趣是否有任何SDK方法来检查字符而不尝试将其附加到输入控件中。

There's no SDK method to check the incoming char. 没有SDK方法可以检查传入的字符。 You'll have to query the restrict text (ideally on the changing event). 您必须查询restrict文本(最好是在changing事件上)。

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. 正是文本显示控件(如RichEditableText用于处理restrict属性的方法。

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. 无论如何,它都在StringUtil.restrict内部使用,因此使用StringUtil.restrict代替testCharacter会产生相同的结果,但会增加性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM