微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flex restrict 输入限制

Flex中TextInput和TextArea有一个比较有用的属性restrict(约束,限定),看下面例子: 1,<mx:extInput id="test_ti" width="160" maxChars="20" restrict="0-9" text="0"/> 这样,这个输入框最多只能输入20个字符,只能输入0到9之间的数字了,你如果输入别的是输入不进去的 2,<mx:extInput id="test_ti" width="160" maxChars="20" restrict="0-9\." text="0"/> 这样,输入框可以输入0到9之间的数字,以及输入'.',中间必须用'\'分隔开来 3,<mx:extInput id="test_ti" width="160" restrict="0-9\ab" text="0"/>这样,以及a,或b 4,<mx:extInput id="test_ti" width="160" restrict="a-z" text="0"/> 可以输入a到z之间任何一个英文字母,'-'表示区间,如果要输入'-',就必须加'\',如\- 结论: 用restrict有个好处,就是省去了验证的麻烦,比如检验是否为数字,如果加了restrict="0-9",就不需要检验了,因为这个输入框只能输入0到9之间的数字,别的输不进去 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:x="http://ns.adobe.com/mxml/2009"       xmlns:s="library://ns.adobe.com/flex/spark"       xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" backgroundColor="#A7E460"> <s:layout>   <s:BasicLayout/> </s:layout> <fx:eclarations>   <!-- Place non-visual elements (e.g.,services,value objects) here --> </fx:eclarations> <s:extInput x="167" y="190" restrict="0-9"/> <s:abel x="70" y="190" text="只能输入数字" width="89" height="22" /> <s:abel x="70" y="234" text="只能输入字母" width="89" height="23"/> <s:TextInput x="167" y="234" restrict="A-Z"/> </s:Application>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐